rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
382 stars 73 forks source link

RuntimeError: Session is closed #283

Open luzik opened 1 year ago

luzik commented 1 year ago

This happens to me first time.

Logger: aiohttp.server
Source: custom_components/dahua/digest.py:46
Integration: Dahua ([documentation](https://github.com/rroller/dahua), [issues](https://github.com/rroller/dahua/issues))
First occurred: 12:21:24 (2 occurrences)
Last logged: 12:22:34
Error handling request

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 735, in get
    return await self.handle(request, camera)
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 753, in handle
    image = await _async_get_image(
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 172, in _async_get_image
    if image_bytes := await camera.async_camera_image(
  File "/config/custom_components/dahua/camera.py", line 243, in async_camera_image
    return await self._coordinator.client.async_get_snapshot(self._channel_number)
  File "/config/custom_components/dahua/client.py", line 74, in async_get_snapshot
    return await self.get_bytes(url)
  File "/config/custom_components/dahua/client.py", line 730, in get_bytes
    response = await auth.request("GET", self._base + url)
  File "/config/custom_components/dahua/digest.py", line 46, in request
    response = await self.session.request(method, url, headers=headers, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 400, in _request
    raise RuntimeError("Session is closed")
RuntimeError: Session is closed

And after that

Exception fetching information from http://192.168.124.30:80/cgi-bin/configManager.cgi?action=getConfig&name=MotionDetect
Exception fetching information from http://192.168.124.30:80/cgi-bin/configManager.cgi?action=getConfig&name=Lighting[0][0]
Exception fetching information from http://192.168.124.30:80/cgi-bin/configManager.cgi?action=getConfig&name=DisableLinkage
Failed to sync device state for 192.168.124.30. See README to enable debug logs to get full exception

Integration manual reload fixed issue, but until reload I wasn't able to open my doors - that was quite a big problem !

Maybe self reload when this exception happens ?

lupus2k commented 1 year ago

I am having the same problem for about 1 week, and I confirm that reloading the device solves it

thornygravy commented 1 year ago

same here, rolled back :(

stefanoferrario commented 1 year ago

same here, rolled back :(

Hi, have you rolled back to which version? I have the same problem and motion detection is blocked after this error

thornygravy commented 1 year ago

same here, rolled back :(

Hi, have you rolled back to which version? I have the same problem and motion detection is blocked after this error

0.9.44

rroller commented 1 year ago

Thanks everyone. I'll try to look at this ASAP

stefanoferrario commented 1 year ago

Rolling back to this version caused HA crashes and I need to restart home assistant several times. I update again and home assistant crashes stop. So I have motion detect problem again… I have many light automations with motion detect sensors

stefanoferrario commented 1 year ago

Hi @rroller in my log I can see that one of the last call is to a python file

2023-06-10 22:01:06.425 DEBUG (MainThread) [custom_components.dahua] Could not get profile mode Traceback (most recent call last): File "/config/custom_components/dahua/__init__.py", line 312, in _async_update_data_int mode_data = await self.client.async_get_video_in_mode() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dahua/client.py", line 546, in async_get_video_in_mode return await self.get(url) ^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dahua/client.py", line 767, in get raise exception File "/config/custom_components/dahua/client.py", line 746, in get response = await auth.request("GET", url) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dahua/digest.py", line 46, in request response = await self.session.request(method, url, headers=headers, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 400, in _request raise RuntimeError("Session is closed")

I have another plugin blocked because of the new Home Assistant version python problem: https://github.com/home-assistant/docker-base/pull/222.

Maybe this cloud help you find out the problem

Thanks

prabhjotsbhatia-ca commented 1 year ago

Another report, not sure if this would be helpful:

Logger: aiohttp.server
Source: custom_components/dahua/digest.py:46
Integration: Dahua ([documentation](https://github.com/rroller/dahua), [issues](https://github.com/rroller/dahua/issues))
First occurred: June 23, 2023 at 11:25:29 PM (160 occurrences)
Last logged: June 23, 2023 at 11:33:06 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 738, in get
    return await self.handle(request, camera)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 756, in handle
    image = await _async_get_image(
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 172, in _async_get_image
    if image_bytes := await camera.async_camera_image(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/camera.py", line 243, in async_camera_image
    return await self._coordinator.client.async_get_snapshot(self._channel_number)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/client.py", line 74, in async_get_snapshot
    return await self.get_bytes(url)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/client.py", line 730, in get_bytes
    response = await auth.request("GET", self._base + url)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/dahua/digest.py", line 46, in request
    response = await self.session.request(method, url, headers=headers, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 400, in _request
    raise RuntimeError("Session is closed")
RuntimeError: Session is closed
stefanoferrario commented 1 year ago

@prabhjotsbhatia-ca yes same error here!