Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIOHTTP ConnectionResetError On Camera Close after 3.3.0 #14919

Closed
mezz64 opened this issue Jun 11, 2018 · 3 comments · Fixed by #15028
Closed

AIOHTTP ConnectionResetError On Camera Close after 3.3.0 #14919

mezz64 opened this issue Jun 11, 2018 · 3 comments · Fixed by #15028

Comments

@mezz64
Copy link
Contributor

mezz64 commented Jun 11, 2018

Home Assistant release with the issue:

Latest Dev Docker Build - 6/10/18

Last working Home Assistant release (if known):
Any build prior to bumping aiohttp to version 3.3.0.

Operating environment (Hass.io/Docker/Windows/etc.):

Docker

Component/platform:

Main mjpeg camera platform and proxy camera platform were tested.

Description of problem:
On closing a stream from the mjpeg camera platform the below error is generated in the log. Functionality is as intended however with no odd behavior. The proxy platform is a little more troublesome in that the same error gets generated constantly multiple times per second when it is active.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

Traceback (if applicable):

2018-06-10 22:04:53 ERROR (MainThread) [aiohttp.server] Unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 398, in start
    await resp.prepare(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 300, in prepare
    return await self._start(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 605, in _start
    return await super()._start(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 367, in _start
    await writer.write_headers(status_line, headers)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/http_writer.py", line 100, in write_headers
    self._write(buf)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/http_writer.py", line 57, in _write
    raise ConnectionResetError('Cannot write to closing transport')
ConnectionResetError: Cannot write to closing transport

Additional information:

@awarecan
Copy link
Contributor

awarecan commented Jun 16, 2018

aio-libs/aiohttp#2499 Add an exception using asyncio.CancelledError
aio-libs/aiohttp#2646 Change exception type to ConnectionResetError (released in aiohttp 3.3.0)

Current aiohttp_client swallowed asyncio.CancelledError, but not ConnectionResetError

https://github.com/home-assistant/home-assistant/blob/722c27f1e2f83e723070e1aff9c826fd78c98f6a/homeassistant/helpers/aiohttp_client.py#L125-L127

To resolve it in root, we should check if response is closing before write to it.

@awarecan
Copy link
Contributor

awarecan commented Jun 17, 2018

OK, I can reproduce it by just use demo camera, now I can verify my fix.

Here is the reproduced error log on demo camera. Click to demo camera card to open more-info window watch the stream, then close the window. Got following logs:

2018-06-17 11:30:00 INFO (MainThread) [homeassistant.components.http.view] Serving /api/camera_proxy_stream/camera.demo_camera to 127.0.0.1 (auth: False)
2018-06-17 11:30:05 DEBUG (MainThread) [homeassistant.components.camera] Stream closed by frontend.
2018-06-17 11:30:05 ERROR (MainThread) [aiohttp.server] Unhandled exception
Traceback (most recent call last):
  File "/home/jason/ha/home-assistant/venv/lib/python3.6/site-packages/aiohttp-3.3.0-py3.6-linux-x86_64.egg/aiohttp/web_protocol.py", line 398, in start
    await resp.prepare(request)
  File "/home/jason/ha/home-assistant/venv/lib/python3.6/site-packages/aiohttp-3.3.0-py3.6-linux-x86_64.egg/aiohttp/web_response.py", line 300, in prepare
    return await self._start(request)
  File "/home/jason/ha/home-assistant/venv/lib/python3.6/site-packages/aiohttp-3.3.0-py3.6-linux-x86_64.egg/aiohttp/web_response.py", line 605, in _start
    return await super()._start(request)
  File "/home/jason/ha/home-assistant/venv/lib/python3.6/site-packages/aiohttp-3.3.0-py3.6-linux-x86_64.egg/aiohttp/web_response.py", line 367, in _start
    await writer.write_headers(status_line, headers)
  File "/home/jason/ha/home-assistant/venv/lib/python3.6/site-packages/aiohttp-3.3.0-py3.6-linux-x86_64.egg/aiohttp/http_writer.py", line 100, in write_headers
    self._write(buf)
  File "/home/jason/ha/home-assistant/venv/lib/python3.6/site-packages/aiohttp-3.3.0-py3.6-linux-x86_64.egg/aiohttp/http_writer.py", line 57, in _write
    raise ConnectionResetError('Cannot write to closing transport')
ConnectionResetError: Cannot write to closing transport

awarecan added a commit to awarecan/home-assistant that referenced this issue Jun 17, 2018
awarecan added a commit to awarecan/home-assistant that referenced this issue Jun 17, 2018
@ghost ghost added the in progress label Jun 17, 2018
@mezz64
Copy link
Contributor Author

mezz64 commented Jun 18, 2018

Thanks for looking into this. I'll try to find some time to test this fix tonight.

@ghost ghost removed the in progress label Jun 25, 2018
pvizeli added a commit that referenced this issue Jun 25, 2018
balloob pushed a commit that referenced this issue Jun 25, 2018
…end (#15028)

* Fix #14919. Should throw exception when camera stream closed by frontend

* Re-trigger CI

* pythonic re-raise
pvizeli added a commit that referenced this issue Jun 25, 2018
* Revert "Fix #14919. Should throw exception when camera stream closed by frontend (#15028)"

This reverts commit 508d045.

* Revert "Fix pylintrc section order and option placements (#15120)"

This reverts commit dbae410.

* Revert "Add storage helper and migrate config entries (#15045)"

This reverts commit ae51dc0.

* Revert "Add language to dark sky weather component (#15130)"

This reverts commit 672a3c7.
eavanvalkenburg pushed a commit to eavanvalkenburg/home-assistant that referenced this issue Jun 28, 2018
…losed by frontend (home-assistant#15028)

* Fix home-assistant#14919. Should throw exception when camera stream closed by frontend

* Re-trigger CI

* pythonic re-raise
eavanvalkenburg pushed a commit to eavanvalkenburg/home-assistant that referenced this issue Jun 28, 2018
…5142)

* Revert "Fix home-assistant#14919. Should throw exception when camera stream closed by frontend (home-assistant#15028)"

This reverts commit 508d045.

* Revert "Fix pylintrc section order and option placements (home-assistant#15120)"

This reverts commit dbae410.

* Revert "Add storage helper and migrate config entries (home-assistant#15045)"

This reverts commit ae51dc0.

* Revert "Add language to dark sky weather component (home-assistant#15130)"

This reverts commit 672a3c7.
@balloob balloob mentioned this issue Jul 6, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this issue Sep 4, 2018
…losed by frontend (home-assistant#15028)

* Fix home-assistant#14919. Should throw exception when camera stream closed by frontend

* Re-trigger CI

* pythonic re-raise
girlpunk pushed a commit to girlpunk/home-assistant that referenced this issue Sep 4, 2018
…5142)

* Revert "Fix home-assistant#14919. Should throw exception when camera stream closed by frontend (home-assistant#15028)"

This reverts commit 508d045.

* Revert "Fix pylintrc section order and option placements (home-assistant#15120)"

This reverts commit dbae410.

* Revert "Add storage helper and migrate config entries (home-assistant#15045)"

This reverts commit ae51dc0.

* Revert "Add language to dark sky weather component (home-assistant#15130)"

This reverts commit 672a3c7.
@home-assistant home-assistant locked and limited conversation to collaborators Oct 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants