core: Errors with stream component and HA hangs up
Home Assistant release with the issue: 0.91.1
Last working Home Assistant release (if known): None
Operating environment (Hass.io/Docker/Windows/etc.): RPi 3B/Raspbian/Python 3.7.2/venv
Component/platform: stream, camera/generic
Description of problem: I use generic camera and stream component. When I tap on camera card in Lovelace on iPad (iOS app 1.5) I have errors in log, stream don’t start and sometimes after that my HA hangs up. The frontend doesn’t work, the light control automation doesn’t start, systemctl shows that the HA service is active (running). I have to restart HA to using it. This is the first time HA has been hanging since I use it (2 years).
Problem-relevant configuration.yaml
entries and (fill out even if it seems unimportant):
camera:
- platform: generic
name: 'Salon'
still_image_url: http://<camera_ip>/cgi-bin/currentpic.cgi
stream_source: rtsp://<camera_ip>:8554/unicast
stream:
Traceback (if applicable):
2019-04-06 13:02:41 ERROR (stream_worker) [libav.mpegts] H.264 bitstream malformed, no startcode found, use the video bitstream filter 'h264_mp4toannexb' to fix it ('-bsf:v h264_mp4toannexb' option with ffmpeg)
2019-04-06 13:04:53 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
resp = await task
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
resp = await handler(request)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/real_ip.py", line 33, in real_ip_middleware
return await handler(request)
File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/ban.py", line 68, in ban_middleware
return await handler(request)
File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/auth.py", line 216, in auth_middleware
return await handler(request)
File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/view.py", line 114, in handle
result = await result
File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/websocket_api/http.py", line 36, in get
request.app['hass'], request).async_handle()
File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/websocket_api/http.py", line 188, in async_handle
await self._writer_task
File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/websocket_api/http.py", line 63, in _writer
await self.wsock.send_json(message, dumps=JSON_DUMP)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_ws.py", line 296, in send_json
await self.send_str(dumps(data), compress=compress)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_ws.py", line 283, in send_str
await self._writer.send(data, binary=False, compress=compress)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/http_websocket.py", line 643, in send
await self._send_frame(message, WSMsgType.TEXT, compress)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/http_websocket.py", line 620, in _send_frame
await self.protocol._drain_helper()
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/base_protocol.py", line 81, in _drain_helper
await waiter
File "/usr/local/lib/python3.7/asyncio/selector_events.py", line 801, in _read_ready__data_received
data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
2019-04-06 13:04:53 ERROR (MainThread) [aiohttp.server] Unhandled exception
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 447, in start
await resp.prepare(request)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_response.py", line 353, in prepare
return await self._start(request)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_response.py", line 667, in _start
return await super()._start(request)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_response.py", line 410, in _start
await writer.write_headers(status_line, headers)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/http_writer.py", line 112, in write_headers
self._write(buf)
File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/http_writer.py", line 67, in _write
raise ConnectionResetError('Cannot write to closing transport')
ConnectionResetError: Cannot write to closing transport
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 73 (22 by maintainers)
It sounds like the general theme is cameras with flaky connections that we are currently processing. Likely due to not properly handling dropped connections. That gives me something to work off of and reproduce, but all my cameras are hardwired, and I haven’t had any issues… so I will need to force a disconnect 😆
I don’t think this is fixed. I"m on 0.92.0 and experiencing the same thing if I have a preloaded stream.
Instead of re-opening this ticket (which at this point is over a year old and contains MANY different error messages), let’s create specific individual issues for each distinctive error message in the log file.
still persistant in 0.104.1
I believe this is caused by cameras losing connectivity, which might be solved by #23617. If I can have help testing after beta is cut, that would be great.
@hunterjm you are spot on with that assessment with the stream dropping. I did a very simple test just now. I loaded up a stream in my dev HA instance and after 1 minute I pulled the power on the camera. I waited 30 seconds and plugged it back in. HA was frozen from that point on and nothing would load, not even the system logs. Here are the logs from this experience.
https://hastebin.com/amuwedazeq.cs
This is what HA looks like when it froze and I tried to look at the logs in the UI
Still persists in 0.102.2
The issue remains on 0.101.3:
In the worker https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/stream/worker.py#L73 you raise an error if no dts, instead of the PyAV developer said:
http://docs.mikeboers.com/pyav/develop/cookbook/basics.html?highlight=dts
Same for me
I have yi with hacks v4 and few minutes fter opening the strem in lovelace it will hung hassio. Using the latest version, so problem is still here, and camera does not loose connection, stream works well outside hass.
I think we have fix #22982