chrysn / aiocoap

The Python CoAP library
Other
267 stars 120 forks source link

handleMessage missing argument + RuntimeError('Event loop is closed') #94

Open infernix opened 7 years ago

infernix commented 7 years ago

On 3286f48f0b949901c8b5c04c0719dc54ab63d431, when running ./aiocoap-client -v coaps://192.168.0.18:5684/.well-known/core against an IKEA Tradfri gateway, I get:

ERROR:asyncio:Exception in callback _SelectorDatagramTransport._read_ready()
handle: <Handle _SelectorDatagramTransport._read_ready()>
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/events.py", line 126, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 1077, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/usr/src/aiocoap/aiocoap/transports/tinydtls.py", line 262, in datagram_received
    self.parent._dtls_socket.handleMessage(self.parent._connection, data)
  File "dtls.pyx", line 258, in dtls.DTLS.handleMessage (dtls.c:5517)
TypeError: handleMessage() takes exactly 3 positional arguments (2 given)

I replaced the secretPSK with the devices api key but it yields the same result.

Wireshark shows:

  104 27.015027336  192.168.0.1 → 192.168.0.18 DTLSv1.2 109 Client Hello
  105 27.015177493 192.168.0.18 → 192.168.0.1  DTLSv1.2 102 Hello Verify Request

If I apply this diff (FYI I have no idea what it is expecting there so I just added 0)

diff --git a/aiocoap/transports/tinydtls.py b/aiocoap/transports/tinydtls.py
index 8057abf..71b3d2f 100644
--- a/aiocoap/transports/tinydtls.py
+++ b/aiocoap/transports/tinydtls.py
@@ -259,7 +259,7 @@ class DTLSClientConnection(interfaces.EndpointAddress):
             self.parent._task.cancel()

         def datagram_received(self, data, addr):
-            self.parent._dtls_socket.handleMessage(self.parent._connection, data)
+            self.parent._dtls_socket.handleMessage(self.parent._connection, data, 0)

 class TransportEndpointTinyDTLS(interfaces.TransportEndpoint):
     def __init__(self, new_message_callback, new_error_callback, log, loop):

It does not throw this error any longer, but then it throws an error I'm also seeing with Home Assistant (reported here https://github.com/home-assistant/home-assistant/issues/9778)

decrypt_verify(): found 24 bytes cleartext
decrypt_verify(): found 770 bytes cleartext
<//15001/65536>;ct=0;obs,<//15001/65540>;ct=0;obs,<//15001/65538>;ct=0;obs,<//15001/65537>;ct=0;obs,<//15001/65541>;ct=0;obs,<//15001/65539>;ct=0;obs,<//15001/65542>;ct=0;obs,<//15004/138319>;ct=0;obs,<//15005/138319>;ct=0;obs,<//15005/138319/200548>;ct=0;obs,<//15005/138319/201928>;ct=0;obs,<//15005/138319/210846>;ct=0;obs,<//15005/138319/196836>;ct=0;obs,<//15005/138319/228499>;ct=0;obs,<//15005/138319/207315>;ct=0;obs,<//15005/138319/228341>;ct=0;obs,<//15001>;ct=0;obs,<//15001/reset>;ct=0,<//status>;ct=0;obs,<//15005>;ct=0;obs,<//15004>;ct=0;obs,<//15004/add>;ct=0,<//15004/remove>;ct=0,<//15006>;ct=0;obs,<//15011/15012>;ct=0;obs,<//15011/9034>;ct=0,<//15011/9030>;ct=0,<//15011/9031>;ct=0,<//15011/9063>;ct=0,<//15011/9033>;ct=0,<//15010>;ct=0;obs
(No newline at end of message)
ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending coro=<DTLSClientConnection._run() running at /usr/src/aiocoap/aiocoap/transports/tinydtls.py:160> wait_for=<Future pending cb=[Task._wakeup()]>>
ERROR:coap:Exception RuntimeError('Event loop is closed',) can not be represented as errno, setting -1.
WARNING:coap:Error received in UDP connection under DTLS: [Errno 9] Bad file descriptor
Exception ignored in: <generator object DTLSClientConnection._run at 0x7fd8a6d12200>
Traceback (most recent call last):
  File "/usr/src/aiocoap/aiocoap/transports/tinydtls.py", line 180, in _run
  File "/usr/lib/python3.5/asyncio/selector_events.py", line 622, in close
  File "/usr/lib/python3.5/asyncio/base_events.py", line 572, in call_soon
  File "/usr/lib/python3.5/asyncio/base_events.py", line 357, in _check_closed
RuntimeError: Event loop is closed
infernix commented 7 years ago

FWIW the issue with the handleMessage args was on what I think is an older fork of tinydtls; on 0.1.3, that issue does not occur but the second one remains.

LarsAC commented 6 years ago

Has this been solved ? I am experiencing the same error, using aiocoap-client as well as from home-assistant. Installed aiocoap==0.3.0.

Lars

HRogge commented 4 years ago

FWIW, I am getting the same exception in my aiocoap server when pressing CTRL+c.