In the context of the Golioth SDK, what events cause the CoAP/DTLS session to terminate?
A CoAP/DTLS session only terminates when the underlying DTLS socket is closed. This can happen due to an explicit teardown by the application (e.g. golioth_client_stop()
, reboot, modem sleep), a network loss, DTLS errors, or when a carrier NAT/CGN closes the UDP mapping after a period of inactivity.
I would assume that after some period of inactivity for an existing session, the client/server assume the session is dead and drop it.
On the server side, there is an inactivity timer: if no traffic is seen for a while, the server will proactively close the DTLS session. In practice, though, what most often forces a reconnect on devices is the network path — for example, carrier NAT/CGN expiring the UDP mapping after a few minutes of inactivity. From the device’s point of view, both of these (server inactivity timeout or NAT expiry) look the same: the socket stops working and a new handshake is required
On the device side, what does CONFIG_GOLIOTH_COAP_CLIENT_RX_TIMEOUT_SEC
do? When this timer expires, does the client establish a new DTLS session and resubscribe all observations?
This Kconfig symbol controls how long the client waits for a response after sending a CoAP request. If the timeout expires, that request fails (you’ll get a timeout error), but the DTLS session is not torn down automatically. The client does not re-handshake or resubscribe just because this timer fired. A new DTLS session (and re-subscription) only happens if the socket itself fails (e.g. network drop, NAT timeout, DTLS error) or if you explicitly stop/restart the client.
What events will cause the Golioth client to explicitly terminate the session? Are there any besides golioth_client_stop()
?
From the Golioth SDK perspective, the only explicit teardown is triggered by the application (e.g. golioth_client_stop()
, reboot, or modem sleep that drops the IP context). Other causes such as network loss, DTLS errors, or carrier NAT/CGN closing the UDP mapping are external to the SDK but will also lead to the session being lost and a re-handshake being required.
How is Stream data sent in this case? Is Connection ID (CID) used? For a sleepy device, does the server require a new CID after some timeout?
Stream data is sent as a normal CoAP request over DTLS. If DTLS Connection ID (CID) is enabled, the CID is included so the server can associate packets with the existing DTLS session, even if the device’s IP or port has changed. This avoids unnecessary handshakes when the IP changes. There is no separate “CID timeout” enforced on the server side — the CID remains valid as long as the DTLS session is valid.
For devices that sleep for long periods, the best practice is to stop the client before sleep and start it again on wake. This ensures a clean handshake and re-establishes Settings/OTA observations.