Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keeping DTLS session alive #337

Open
anyc opened this issue Jan 23, 2024 · 1 comment
Open

Keeping DTLS session alive #337

anyc opened this issue Jan 23, 2024 · 1 comment

Comments

@anyc
Copy link

anyc commented Jan 23, 2024

Hello,

I created a client context with create_client_context() and send GET requests using Message() and ctx.request() from time to time. On the server side (libcoap), I noticed that the session is closed immediately after the request and on the client side, I see that a new connection is started on every request:

INFO:coap:No DTLS connection active to (192.168.0.1, 5684, b'user'), creating one

The context is stored in an object that is referenced so the same context should stay "open" during application runtime. For my experimental protocol, it is necessary that the session stays open between requests as the server stores a list of held locks and they are released automatically when the session closes.

Hence, is there a way to keep a (DTLS) session open until it is explicitly shutdown or the context is "garbage collected"?

I started pdb inside the tinydtls _remove_from_pool() method to find out who shuts down the connection but it looks like this is just a task that was scheduled somewhere else:

[...]
-> self.loop.run_forever()
  /usr/lib/python3.11/asyncio/base_events.py(607)run_forever()
-> self._run_once()
  /usr/lib/python3.11/asyncio/base_events.py(1923)_run_once()
-> handle = None  # Needed to break cycles when an exception occurs.
  /home/coap/venv/lib/python3.11/site-packages/aiocoap/transports/tinydtls.py(261)__del__()
-> self.shutdown()
> /home/coap/venv/lib/python3.11/site-packages/aiocoap/transports/tinydtls.py(241)shutdown()
-> self._remove_from_pool()

Thank you!

Python version: 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0]
aiocoap version: 0.4.7
Modules missing for subsystems:
    dtls: everything there
    oscore: missing cbor2, cryptography, filelock, ge25519
    linkheader: everything there
    prettyprint: missing cbor2, termcolor, pygments
Python platform: linux
Default server transports:  tinydtls:tcpserver:tcpclient:tlsserver:tlsclient:udp6
Selected server transports: tinydtls:tcpserver:tcpclient:tlsserver:tlsclient:udp6
Default client transports:  tinydtls:tcpclient:tlsclient:udp6
Selected client transports: tinydtls:tcpclient:tlsclient:udp6
SO_REUSEPORT available (default, selected): True, True
@anyc
Copy link
Author

anyc commented Jan 25, 2024

Looks like the session stays open if I keep the last response from await ctx.request(myreq).response referenced somewhere. I can live with this but more explicit control over this behavior would be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant