chrysn/aiocoap

Intermittent errors after upgrading to 0.4.5

Closed this issue · 5 comments

Since upgrading to 0.4.5, one of the custom integrations has intermittent errors. See below logs of OSError: [Errno 22] Invalid argument and OSError: [Errno 24] Too many open files

Reverting back to 0.4.4 fixed it.

Python version: 3.10.5 (main, Jul 17 2022, 19:00:22) [GCC 10.2.1 20210110]
aiocoap version: 0.4.5
Modules missing for subsystems:
dtls: missing DTLSSocket
oscore: missing cbor2, filelock, ge25519
linkheader: missing LinkHeader
prettyprint: missing LinkHeader, cbor2, termcolor
Python platform: linux
Default server transports: tcpserver:tcpclient:tlsserver:tlsclient:ws:udp6
Selected server transports: tcpserver:tcpclient:tlsserver:tlsclient:ws:udp6
Default client transports: tcpclient:tlsclient:ws:udp6
Selected client transports: tcpclient:tlsclient:ws:udp6
SO_REUSEPORT available (default, selected): True, True

Dec 4 03:49:19 XXXXX: 2022-12-04 03:49:19.206 ERROR (MainThread) [custom_components.philips_airpurifier_coap.fan] init_connection(): Exception!
Dec 4 03:49:19 XXXXX: Traceback (most recent call last):
Dec 4 03:49:19 XXXXX: File "/home/homeassistant/ha3/.homeassistant/custom_components/philips_airpurifier_coap/fan.py", line 385, in init
Dec 4 03:49:19 XXXXX: await self._connect_task
Dec 4 03:49:19 XXXXX: File "/home/homeassistant/ha3/.homeassistant/custom_components/philips_airpurifier_coap/fan.py", line 368, in init_connection
Dec 4 03:49:19 XXXXX: self._client = await CoAPClient.create(self._host)
Dec 4 03:49:19 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aioairctrl/coap/client.py", line 38, in create
Dec 4 03:49:19 XXXXX: await obj._init()
Dec 4 03:49:19 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aioairctrl/coap/client.py", line 33, in _init
Dec 4 03:49:19 XXXXX: await self._sync()
Dec 4 03:49:19 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aioairctrl/coap/client.py", line 54, in _sync
Dec 4 03:49:19 XXXXX: response = await self._client_context.request(request).response
Dec 4 03:49:19 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aiocoap/protocol.py", line 612, in _run_outer
Dec 4 03:49:19 XXXXX: await cls._run(app_request, response, weak_observation, protocol, log)
Dec 4 03:49:19 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aiocoap/protocol.py", line 637, in _run
Dec 4 03:49:19 XXXXX: await protocol.find_remote_and_interface(app_request)
Dec 4 03:49:19 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aiocoap/protocol.py", line 340, in find_remote_and_interface
Dec 4 03:49:19 XXXXX: if await ri.fill_or_recognize_remote(message):
Dec 4 03:49:19 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aiocoap/tokenmanager.py", line 205, in fill_or_recognize_remote
Dec 4 03:49:19 XXXXX: return await self.token_interface.fill_or_recognize_remote(message)
Dec 4 03:49:19 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aiocoap/messagemanager.py", line 351, in fill_or_recognize_remote
Dec 4 03:49:19 XXXXX: remote = await self.message_interface.determine_remote(message)
Dec 4 03:49:19 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aiocoap/transports/udp6.py", line 397, in determine_remote
Dec 4 03:49:19 XXXXX: addrinfo = await self.loop.getaddrinfo(
Dec 4 03:49:19 XXXXX: File "/usr/local/lib/python3.10/asyncio/base_events.py", line 860, in getaddrinfo
Dec 4 03:49:19 XXXXX: return await self.run_in_executor(
Dec 4 03:49:19 XXXXX: File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
Dec 4 03:49:19 XXXXX: result = self.fn(*self.args, **self.kwargs)
Dec 4 03:49:19 XXXXX: File "/usr/local/lib/python3.10/socket.py", line 955, in getaddrinfo
Dec 4 03:49:19 XXXXX: for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
Dec 4 03:49:19 XXXXX: OSError: [Errno 22] Invalid argument
Dec 4 03:49:20 XXXXX: 2022-12-04 03:49:20.226 ERROR (MainThread) [custom_components.philips_airpurifier_coap.fan] init_connection(): Exception!
Dec 4 03:49:20 XXXXX: Traceback (most recent call last):
Dec 4 03:49:20 XXXXX: File "/home/homeassistant/ha3/.homeassistant/custom_components/philips_airpurifier_coap/fan.py", line 385, in init
Dec 4 03:49:20 XXXXX: await self._connect_task
Dec 4 03:49:20 XXXXX: File "/home/homeassistant/ha3/.homeassistant/custom_components/philips_airpurifier_coap/fan.py", line 368, in init_connection
Dec 4 03:49:20 XXXXX: self._client = await CoAPClient.create(self._host)
Dec 4 03:49:20 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aioairctrl/coap/client.py", line 38, in create
Dec 4 03:49:20 XXXXX: await obj._init()
Dec 4 03:49:20 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aioairctrl/coap/client.py", line 31, in _init
Dec 4 03:49:20 XXXXX: self._client_context = await Context.create_client_context()
Dec 4 03:49:20 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aiocoap/protocol.py", line 176, in create_client_context
Dec 4 03:49:20 XXXXX: await self._append_tokenmanaged_messagemanaged_transport(
Dec 4 03:49:20 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aiocoap/protocol.py", line 142, in _append_tokenmanaged_messagemanaged_transport
Dec 4 03:49:20 XXXXX: transport = await message_interface_constructor(mman)
Dec 4 03:49:20 XXXXX: File "/srv/hass1/lib/python3.10/site-packages/aiocoap/transports/udp6.py", line 303, in create_client_transport_endpoint
Dec 4 03:49:20 XXXXX: sock = socket.socket(family=socket.AF_INET6, type=socket.SOCK_DGRAM)
Dec 4 03:49:20 XXXXX: File "/usr/local/lib/python3.10/socket.py", line 232, in init
Dec 4 03:49:20 XXXXX: _socket.socket.init(self, family, type, proto, fileno)
Dec 4 03:49:20 XXXXX: OSError: [Errno 24] Too many open files

debugging some more, closed for now

If you get too many file descriptprs, chances are you're opening too many CoAP contexts; except for very few occasions, a single context should suffice for an application, and you should not need, like 1000 (which is roughly the default limit of file descriptors). Does create_client_context get called in your application more than once?

By the way, whose version 2022.11.x is this referring to? Ubuntu has no release of that name, and it isn't an aiocoap version number either.

@joe-sydney is talking about Home Assistant

Thanks @kongo09.

Yes, apologies, I got confused with all the github repositories that I've been following, and forgot to mention Home Assistant.

However, .... on further debugging, I now suspect that the change that actually triggered these issues was the change to aiocoap 0.4.5 which happened automatically. I believe 0.4.5 was released 13 days ago.

I am now reverting back to previous releases to see if the issues go away. I'll give it a few days before reporting back.

Reverting back to 0.4.4 did fix my issues. There might have been some breaking changes. I'll close this issue and keep using 0.4.4 for now.