pyHik icon indicating copy to clipboard operation
pyHik copied to clipboard

Fix last line of stream being stuck in buffer

Open BlindChickens opened this issue 2 years ago • 2 comments

requests.Response.iter_lines has a known issue where it will not return a line if the bytes in that line is less than the minimum size and it's the last line. https://github.com/psf/requests/issues/3577

In my case it caused events to only be picked up when the next event came in from the DVR. So the motion event would only register when the next videoloss event came in or some other event.

Basically means the latest event is just never picked up. The second latest event according to the DVR will alway be the last one interpreted by the library.

In real life this caused my motion events to notify my home assistant with considerable lag. Up to 10 seconds.

BlindChickens avatar Jul 06 '22 22:07 BlindChickens

Thanks for the PR! Change looks simple enough. I'll try to find some time this weekend to do some tests and if all is well I'll get it merged and do a version bump.

mezz64 avatar Jul 09 '22 02:07 mezz64

Sorry for the slow response on this. While this change functions fine, I'm not too keen on the performance impact. In my test cases it's 6-7x more resource intensive than the existing implementation. Have you tried doing bigger chunks, yet smaller than the iter_line default to see if we can fix the issue, yet not increase the resources so much?

I don't see this behavior on my cams (the videoloss events are frequent) so it's hard for me to know if a larger chunk will still fix your issue.

mezz64 avatar Sep 03 '22 02:09 mezz64