agsh / onvif

ONVIF node.js implementation
http://agsh.github.io/onvif/
MIT License
679 stars 230 forks source link

adds retry when pull subscriptions fails #319

Closed HarryEMartland closed 1 month ago

HarryEMartland commented 1 month ago

Hi, I am running https://shinobi.video/ which uses this library and have noticed that sometimes the ONVIF events don't get triggered. I narrowed this down to when there is a connection disruption e.g. my router updates or the camera is restarted.

This Pull Requests adds a retry mechanism if the connection fails. I have added a configurable wait time and used that as a kind of feature flag so this change is more backwards compatible.

I struggled to write tests for this due to the timeout and I think the mock server being in an external process. If someone could guide me the best way to test this I would be happy to write some tests.

I have tested this locally adding a listener, restarting my camera and then seeing if events continue to flow

HarryEMartland commented 1 month ago

Just noticed #314 which may solve this too however it does not have a delay. I worry if there is no delay it could consume a lot of CPU retrying.

There may be a happy middle ground where we do some fancy exponential backoff but retry straight away.

agsh commented 1 month ago

@HarryEMartland, hello! Thanks for researching and digging the old code! :smile: And for reminding me about https://github.com/agsh/onvif/pull/314, the connection socket timeout issue for the TP-Link Tapo C220 Yep, these seem to be similar connection issues. There are some points in the callback functions where we can check these errors:

I've created a new PR which combines these two issues. So now it's your turn to review my code :smiling_imp: >>> HERE IT IS <<< Maybe there are still places that stop the pullMessages loop, for example, running ONVIF commands that are not supported by a specific device (such as renew or unsubscribe). Unfortunately, I can’t test it on any device right now, I hope I haven’t forgotten how to program without errors :rofl: