pycyphal icon indicating copy to clipboard operation
pycyphal copied to clipboard

Background workers should terminate if the event loop is closed

Open pavel-kirienko opened this issue 3 years ago • 1 comments
trafficstars

Resource mismanagement may result in the following messages logged endlessly:

ERROR    pycyphal.transport.udp._socket_reader:_socket_reader.py:257 SocketReader(id=0x23dddada8f0, original_fd=2276, socket=<socket.socket fd=2276, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=17, laddr=('0.0.0.0', 16383)>, remote_node_ids=[None]): Worker thread error: Event loop is closed; will continue after a short nap
Traceback (most recent call last):
  File "C:\projects\yakut\.nox\test-3-10\lib\site-packages\pycyphal\transport\udp\_socket_reader.py", line 249, in _thread_entry_point
    loop.call_soon_threadsafe(self._dispatch_frame, ts, source_ip, frame)
  File "C:\Python310-x64\lib\asyncio\base_events.py", line 795, in call_soon_threadsafe
    self._check_closed()
  File "C:\Python310-x64\lib\asyncio\base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Source:

https://github.com/OpenCyphal/pycyphal/blob/4e09c9067208df3e00cd89a4465e7b6b6753b19a/pycyphal/transport/udp/_socket_reader.py#L256-L258

Other locations can be found in the CAN media drivers etc.

Perhaps there should be a counter to terminate the task after X successive errors of the same type.

pavel-kirienko avatar Apr 25 '22 19:04 pavel-kirienko

Actually, a RuntimeError should just bring down the worker unconditionally.

pavel-kirienko avatar Sep 20 '22 07:09 pavel-kirienko