You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TP-Link Tapo C220 (firmware 1.1.6) supports ONVIF pull-point subscriptions but unfortunately sets the socket read timeout on the pull endpoint to 10 seconds - i.e. every pull messages request gets closed by the cam after 10 seconds of I/O inactivity.
I tried changing various timeouts on the network & messages level and using TCP keep-alives to no avail - the cam sends TCP FIN packet roughly 10 seconds after receiving HTTP request headers and the connection gets closed prematurely with ECONNRESET error.
This pull request intercepts ECONNRESET error before it is propagated to event callbacks and restarts the event request loop (which handles subscription expiration, renewal, etc).
I believe the original plan of the author was to handle such cases one level higher - in _eventPull() - by unsubscribing and resubscribing again, but due to a bug in the code (?) unsubscribe() callback is never called and subscription never gets reinitialized.
This code:
this.unsubscribe({}, function(_err,_data,_xml) {
// once the unsubsribe has completed (even if it failed), go around the loop again
this._eventRequest();
});
should probably be without the empty object {} passed as the first parameter of unsubscribe call (the callback parameter).
this.unsubscribe(function(_err,_data,_xml) {
// once the unsubsribe has completed (even if it failed), go around the loop again
this._eventRequest();
});
Edited to add: fix for the above has already been submitted in #310.
In any case, as the subscription is still active at this point , there is no need to go through the unsubscribe/subscribe cycle again until the subscription expires and this is handled automatically by _eventRequest(). Unsubscribe doesn't work in the case of Tapo C220 anyway - the cam returns 500 Internal Server Error. :-)
ECONNRESET handling could be moved to _eventPull(), though. Please advise if any changes are needed.
Hi
Many thanks for this.
Andrew was the original author (I think) and then I re-wrote some of the event subscription code about 18 months ago.
So when I get a chance I'll take a look.
I also have a Tapo C200 and I know someone with the C210.
Many thanks for your contribution. I'll try and take a look later this week.
@akomelj Hello! Thank you very much for pointing out the problem and suggesting a solution! Sorry for the very late answer
Yes, this behavior will help on the connection reset. Event pulling stops when any error occurs and it seems that we need to continue this infinitive loop in the connection trouble case.
And yes, we need to move reconnection code to _eventPull because pullMessages is the public function from the ONVIF specs and can be used somewhere else in the user code.
I'll write the tests for this point and move error catching to _eventPull
BTW I ordered TP-Link Tapo C220 to myself and test it at the next weekend 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TP-Link Tapo C220 (firmware 1.1.6) supports ONVIF pull-point subscriptions but unfortunately sets the socket read timeout on the pull endpoint to 10 seconds - i.e. every pull messages request gets closed by the cam after 10 seconds of I/O inactivity.
I tried changing various timeouts on the network & messages level and using TCP keep-alives to no avail - the cam sends TCP FIN packet roughly 10 seconds after receiving HTTP request headers and the connection gets closed prematurely with
ECONNRESETerror.This pull request intercepts
ECONNRESETerror before it is propagated to event callbacks and restarts the event request loop (which handles subscription expiration, renewal, etc).I believe the original plan of the author was to handle such cases one level higher - in
_eventPull()- by unsubscribing and resubscribing again, but due to a bug in the code (?)unsubscribe()callback is never called and subscription never gets reinitialized.This code:
should probably be without the empty object
{}passed as the first parameter ofunsubscribecall (the callback parameter).Edited to add: fix for the above has already been submitted in #310.
In any case, as the subscription is still active at this point , there is no need to go through the unsubscribe/subscribe cycle again until the subscription expires and this is handled automatically by
_eventRequest(). Unsubscribe doesn't work in the case of Tapo C220 anyway - the cam returns 500 Internal Server Error. :-)ECONNRESEThandling could be moved to_eventPull(), though. Please advise if any changes are needed.