ReneNulschDE / mbapi2020

Custom Component to integrate MercedesME devices into Home-Assistant
Other
149 stars 29 forks source link

Cannot write to closing transport #148

Closed KristianOellegaard closed 9 months ago

KristianOellegaard commented 10 months ago

When trying to set Max SoC I some times get the following in my automation. Restart solves the problem.

Stopped because an error was encountered at November 6, 2023 at 8:37:05 PM (runtime: 0.10 seconds)

Cannot write to closing transport

Any idea what could be wrong?

Joo01 commented 10 months ago

Same issue here!

Logger: homeassistant
Source: custom_components/mbapi2020/websocket.py:164
Integration: MercedesME 2020 (documentation, issues)
First occurred: 7. November 2023 um 10:42:24 (1 occurrences)
Last logged: 7. November 2023 um 10:42:24

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/mbapi2020/websocket.py", line 164, in _recv
    data = await self._connection.receive()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_ws.py", line 265, in receive
    await self.pong(msg.data)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_ws.py", line 146, in pong
    await self._writer.pong(message)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/http_websocket.py", line 670, in pong
    await self._send_frame(message, WSMsgType.PONG)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/http_websocket.py", line 646, in _send_frame
    self._write(header + mask + message)
  File "/usr/local/lib/python3.11/site-packages/aiohttp/http_websocket.py", line 663, in _write
    raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
ReneNulschDE commented 10 months ago

Could you check the logfile if there are other MB2020 messages (Info, Warning, Error) near to the error message? esp lines like these:

INFO (MainThread) [custom_components.mbapi2020.oauth] Start async_refresh_access_token() with refresh_token
INFO (MainThread) [custom_components.mbapi2020.websocket] Watchdog expired – calling _disconnected
INFO (MainThread) [custom_components.mbapi2020.websocket] Connecting to wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/ws
INFO (MainThread) [custom_components.mbapi2020.websocket] Connected to mercedes websocket at wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/ws
ReneNulschDE commented 10 months ago

@KristianOellegaard : Could you share the stack trace please? @Joo01 : The error appears in the ping/pong operation to keep the tunnel open. The pong cant be send when the tunnel gets recreated. Is any operation affected besides the unneeded error message?

ReneNulschDE commented 10 months ago

I have added some additional error handling for this type of error. I'll test it a few days in my environment and will publish a new version next week.

ReneNulschDE commented 9 months ago

Solved with v0.9.6