coap_resource.c: Fix observe callback timing window

If multiple clients subscribe to the same resource, one of the clients
'goes away', the server will eventually close down the session for that client
which will then remove any subscriptions, iterating through the different
resources.

If this happens at the same time that coap_resource_notify_observers() is called
in another thread, and the GET/FETCH handler is called for a common resource
and in particular for the session that is now going away, on return from the
callback the subscription may no longer exist.  This PR fixes this window.

In addition, if the resource subscriber list is being traversed, then a another
call to coap_notify_observers() for the same resource will not generate a new set
unsolicited observe responses for multi-thread protection.

Update
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2025-05-20 15:25:31 +01:00
1 parent 24ec7b19bf
commit 8975c15cd8
3 files changed
+69 -27

No files matched your search

+5
View File
@@ -413,6 +413,11 @@ coap_pdu_t *coap_new_pdu_lkd(coap_pdu_type_t type, coap_pdu_code_t code,
*/
void coap_delete_pdu_lkd(coap_pdu_t *pdu);
COAP_STATIC_INLINE void
coap_pdu_release_lkd(coap_pdu_t *pdu) {
coap_delete_pdu_lkd(pdu);
}
/**
* Duplicate an existing PDU. Specific options can be ignored and not copied
* across. The PDU data payload is not copied across.
+1
View File
@@ -59,6 +59,7 @@ struct coap_resource_t {
unsigned int is_unknown:1; /**< resource created for unknown handler */
unsigned int is_proxy_uri:1; /**< resource created for proxy URI handler */
unsigned int is_reverse_proxy:1; /**< resource created for reverse proxy URI handler */
unsigned int list_being_traversed:1; /**< resource subscriber list being traversed */
/**
* Used to store handlers for the seven coap methods @c GET, @c POST, @c PUT,