ReneNulschDE / mbapi2020

Custom Component to integrate MercedesME devices into Home-Assistant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Other error Cannot write to closing transport

FredericMa opened this issue · comments

The problem

I noticed sensors weren't updating anymore and found this error in the logs: Other error Cannot write to closing transport
After reloading the integration everything worked again. This morning it happened again. I've found the stack trace that has been added below.
I didn't have debug logging enabled but I've now reloaded the integration and enabled the debug logging.

Maybe the end of the stack trace is the interesting part?
RuntimeWarning: coroutine 'Websocket.async_connect' was never awaited

What version of MBAPI2020 do use?

v0.12.0

What was the last working version of MBAPI2020?

No response

What type of installation are you running?

Home Assistant Container

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-03-21 08:00:22.184 ERROR (MainThread) [custom_components.mbapi2020.websocket] Other error Cannot write to closing transport
2024-03-21 08:00:22.193 ERROR (MainThread) [custom_components.mbapi2020.client] Error with the websocket connection: 
2024-03-21 08:00:22.193 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/mbapi2020/websocket.py", line 169, in _start_websocket_handler
    await self._websocket_handler(session)
  File "/config/custom_components/mbapi2020/websocket.py", line 191, in _websocket_handler
    msg = await self._connection.receive()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_ws.py", line 280, in receive
    await self.pong(msg.data)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_ws.py", line 160, in pong
    await self._writer.pong(message)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/http_websocket.py", line 709, in pong
    await self._send_frame(message, WSMsgType.PONG)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/http_websocket.py", line 675, in _send_frame
    self._write(header + mask + message)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/http_websocket.py", line 702, in _write
    raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/mbapi2020/client.py", line 221, in attempt_connect
    await self.websocket.async_connect(on_data)
  File "/config/custom_components/mbapi2020/websocket.py", line 114, in async_connect
    await asyncio.gather(queue_task, websocket_task)
  File "/config/custom_components/mbapi2020/websocket.py", line 178, in _start_websocket_handler
    raise WebsocketError from error
custom_components.mbapi2020.errors.WebsocketError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/mbapi2020/coordinator.py", line 68, in ws_connect
    await self.client.attempt_connect(self.on_dataload_complete)
  File "/config/custom_components/mbapi2020/client.py", line 224, in attempt_connect
    async_call_later(
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1550, in async_call_later
    else HassJob(action, f"call_later {delay}")
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 305, in __init__
    self.job_type = job_type or _get_hassjob_callable_job_type(target)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 338, in _get_hassjob_callable_job_type
    raise ValueError("Coroutine not allowed to be passed to HassJob")
ValueError: Coroutine not allowed to be passed to HassJob
2024-03-21 08:00:22.206 WARNING (MainThread) [py.warnings] /usr/local/lib/python3.12/asyncio/base_events.py:1973: RuntimeWarning: coroutine 'Websocket.async_connect' was never awaited
  handle = self._ready.popleft()

Additional information

No response

I see the same issue after updating the component to v0.12.0. Downgrading to v0.11.1 seems to make the issue disappear again.

Hi Rene,

I've collected a debug log but for privacy concerns I would prefer to send it to you via e-mail.
I've noticed that you don't have a general e-mail address so can you please provide me the mail address you want me to send the log to?

Thanks!

Thx, please send it to mbdev.issue218@nulsch.de.

Fixed with v0.13.0