<p></p>
<p><b>@benpicco</b> commented on this pull request.</p>

<p>I think there is still something wrong here:<br>
When playing around with two native RIOT nodes querying a third native RIOT node with</p>
<pre><code>coap get fe80::7837:fcff:fe7d:1aaf 5684 /.well-known/core
</code></pre>
<p>after a while one of the nodes would no longer receive a response. (This is after the <code>dsm: removed session</code> message), the server shows</p>
<pre><code>CoAP server is listening on port 5684
Connection secured with DTLS
Free DTLS session slots: 1/1
 CLI requests sent: 0
CoAP open requests: 0
Configured Proxy: None
</code></pre>
<p>The clients meanwhile display</p>
<pre><code>CoAP server is listening on port 5684
Connection secured with DTLS
Free DTLS session slots: 13/1
 CLI requests sent: 17
CoAP open requests: 0
Configured Proxy: None
</code></pre>
<p>This number increases with each request that does not receive a response.</p><hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/15549#discussion_r665301181">sys/include/net/gcoap.h</a>:</p>
<pre style='color:#555'>> @@ -917,6 +1004,18 @@ int gcoap_get_resource_list(void *buf, size_t maxlen, uint8_t cf);
 ssize_t gcoap_encode_link(const coap_resource_t *resource, char *buf,
                           size_t maxlen, coap_link_encoder_ctx_t *context);
 
+
</pre>

⬇️ Suggested change
<pre style="color: #555">-
</pre>


<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/15549#discussion_r665301472">sys/net/application_layer/gcoap/gcoap.c</a>:</p>
<pre style='color:#555'>> +            return;
+        }
+        sock_udp_ep_t ep;
+        sock_dtls_session_get_udp_ep(&socket.ctx_dtls_session, &ep);
+        _process_coap_pdu(&socket, &ep,  _listen_buf, res);
+    }
+}
+
+/* Timeout function to free up a session when too many session slots are occupied */
+static void _dtls_free_up_session(void *arg) {
+    (void)arg;
+    sock_dtls_session_t session;
+
+    uint8_t minimum_free = CONFIG_GCOAP_DTLS_MINIMUM_AVAILABLE_SESSIONS;
+    if (dsm_get_num_available_slots() < minimum_free) {
+        if(dsm_get_least_recently_used_session(&_sock_dtls, &session) != -1) {
</pre>

⬇️ Suggested change
<pre style="color: #555">-        if(dsm_get_least_recently_used_session(&_sock_dtls, &session) != -1) {
+        if (dsm_get_least_recently_used_session(&_sock_dtls, &session) != -1) {
</pre>


<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/RIOT-OS/RIOT/pull/15549#pullrequestreview-700913738">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABE7WYB63GYDFJUVDBBNKK3TWQ62HANCNFSM4UL2PR7Q">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABE7WYELPEDHVRP7XXVD6KDTWQ62HA5CNFSM4UL2PR72YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOFHDRQSQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/RIOT-OS/RIOT/pull/15549#pullrequestreview-700913738",
"url": "https://github.com/RIOT-OS/RIOT/pull/15549#pullrequestreview-700913738",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>