aiocoap icon indicating copy to clipboard operation
aiocoap copied to clipboard

AttributeError: 'TCPClient' object has no attribute '_tokenmanager'

Open GeorgeBateman opened this issue 3 years ago • 1 comments

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.

GeorgeBateman avatar May 18 '22 14:05 GeorgeBateman

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.

chrysn avatar Jul 23 '22 12:07 chrysn

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.

chrysn avatar Aug 17 '22 09:08 chrysn

Many thanks!

GeorgeBateman avatar Aug 17 '22 16:08 GeorgeBateman