fwestenberg / reolink

Python Reolink package
MIT License
86 stars 25 forks source link

stream traceback for uncaught error handling #8

Closed mrand closed 3 years ago

mrand commented 3 years ago

Describe the bug Looks like there is an unhandled exception, at a minimum.

More generally, the integration only displays a live feed for a few minutes for me, before the image goes away and I start getting error messages in the log.

To Reproduce Manually installed HA integration from the files in the HA pull request. I'm using 5 GHz wifi to the 511W, so there might be small periods of times where it drops out, although I ran with vlc last night for quite a while and it seemed perfectly fine before adding the reolink integration.

configuration.yaml config for this:

reolink:
stream:

Expected behavior No tracebacks generated

Environment: Please provide useful information about your environment, like:

Additional context

Looking a the traceback closer, I'm not sure if the proper way to handle this is to filter out exceptional values so that the stream component doesn't see them, or if it's actually a problem with the stream component (in which case, if you can figure out how to fix it, I'm sure core would appreciate a PR).

2020-12-06 13:24:42 ERROR (MainThread) [reolink.camera_api] Error translating Reolink settings response
2020-12-06 13:24:52 ERROR (MainThread) [reolink.camera_api] Error translating login response to json
2020-12-06 13:24:52 ERROR (MainThread) [reolink.camera_api] Error translating Reolink state response
2020-12-06 13:26:00 ERROR (stream_worker) [homeassistant.components.stream.worker] Error demuxing stream: [Errno 5] I/O error: 'rtmp://192.168.2.20:1935/bcs/channel0_main.bcs?channel=0&stream=0&token=<some_string_was_here>'
2020-12-06 13:26:00 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 118, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/stream/core.py", line 187, in get
    return await self.handle(request, stream, sequence)
  File "/usr/src/homeassistant/homeassistant/components/stream/hls.py", line 57, in handle
    return web.Response(body=self.render(track).encode("utf-8"), headers=headers)
  File "/usr/src/homeassistant/homeassistant/components/stream/hls.py", line 37, in render
    segment = track.get_segment(track.segments[-1])
IndexError: list index out of range
2020-12-06 13:26:02 ERROR (MainThread) [reolink.camera_api] Error translating Reolink settings response
2020-12-06 13:26:12 ERROR (MainThread) [reolink.camera_api] Error translating login response to json
2020-12-06 13:26:12 ERROR (MainThread) [reolink.camera_api] Error translating Reolink state response
2020-12-06 13:26:56 ERROR (stream_worker) [homeassistant.components.stream.worker] Error demuxing stream: [Errno 1414092869] Immediate exit requested: 'rtmp://192.168.2.20:1935/bcs/channel0_main.bcs?channel=0&stream=0&token=<some-string-was-here>'
2020-12-06 13:27:22 ERROR (MainThread) [reolink.camera_api] Error translating login response to json
2020-12-06 13:27:22 ERROR (MainThread) [reolink.camera_api] Error translating Reolink settings response
2020-12-06 13:27:32 ERROR (MainThread) [reolink.camera_api] Error translating login response to json
fwestenberg commented 3 years ago

Thanks a lot for your report. It looks like some connection problems with the camera. Could this be the main cause? For streaming, I actually use some code many other components also use.

mrand commented 3 years ago

Yes, there may very well be a connection problem - but I went ahead and opened the issues in the hopes that the handling of those could be made more robust (since, after all, connection problems could occur for any number of reasons).

fwestenberg commented 3 years ago

If I change the error to info or debug, the log will stay clean. The camera will reconnect by itself every minute, so when the camera is well connected the problem will be solved by the integration. I have a camera reboot scheduled in the Reolink web interface, and every day again the integration is working.

fwestenberg commented 3 years ago

This issue should be in the Reolink_dev repository, since this is the repository for the Reolink Python package.