aiocoap
aiocoap copied to clipboard
AttributeError: 'TCPClient' object has no attribute '_tokenmanager'
The following code:
p = await Context.create_client_context()
msg = Message(code=GET, uri="coap+tcp://127.0.0.1:5000/")
await p.request(msg).response
await p.shutdown()
results in
Aborting connection: Server shutdown
Exception in callback _SelectorSocketTransport._call_connection_lost(None)
handle: <Handle _SelectorSocketTransport._call_connection_lost(None)>
Traceback (most recent call last):
File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/lib/python3.7/asyncio/selector_events.py", line 916, in _call_connection_lost
super()._call_connection_lost(exc)
File "/usr/lib/python3.7/asyncio/selector_events.py", line 690, in _call_connection_lost
self._protocol.connection_lost(exc)
File "/home/.../.local/lib/python3.7/site-packages/aiocoap/transports/tcp.py", line 167, in connection_lost
self._ctx._dispatch_error(self, exc)
File "/home/.../.local/lib/python3.7/site-packages/aiocoap/transports/tcp.py", line 259, in _dispatch_error
if self._tokenmanager is None:
AttributeError: 'TCPClient' object has no attribute '_tokenmanager'
This is apparently caused by the use of del in https://github.com/chrysn/aiocoap/blob/f81962718d1280193a94ffc8f5515190d75ccc99/aiocoap/transports/tcp.py#L406
That variable should probably be set to None instead.
Yes, I mixed up the values this should have during shutdown.
Thanks for finding, this; I'm still digging around in the code a bit more to find why the tests did not report this.
The reason this was not found in automated tests was because aiocoap-client didn't do proper shutdown. Now on to the underlying issue -- the change you proposed does fix it, but now the lack of proper shutdown for TCP connections start spitting warnings, fixing that.
Many thanks!