Skip to content

Commit 61de3ef

Browse files
committed
fixup: make blocking client func fail on unicoap thread
1 parent ccd2f73 commit 61de3ef

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

sys/net/application_layer/unicoap/client/client.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,24 @@ int unicoap_send_request_sync_copy(unicoap_message_t* request,
328328
assert(buffer);
329329
assert(buffer_capacity > 0);
330330
assert(response);
331+
332+
/* Prevent this function from deadlocking the unicoap thread. No one besides the unicoap
333+
* thread can unlock the mutex below (via the _sync_callback). You cannot have
334+
* a function that waits for the response to arrive while blocking the very same
335+
* thread would process the response.
336+
*
337+
* This is particularly true for applications running unicoap in sync mode. */
338+
if (thread_getpid() == _unicoap_pid) {
339+
if (IS_ACTIVE(CONFIG_UNICOAP_ASSIT)) {
340+
unicoap_assist(API_MISUSE("Attempted to call blocking '%s' on unicoap thread, "
341+
"would block processing loop")
342+
FIXIT("Use 'unicoap_send_request_async' instead"),
343+
__func__);
344+
}
345+
_CLIENT_DEBUG("Attempted to open request on unicoap thread, not blocking.");
346+
assert(false);
347+
return -1;
348+
}
331349

332350
_sync_copy_args_t args = (_sync_copy_args_t) {
333351
.response = response,

sys/net/application_layer/unicoap/include/private/state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ void unicoap_event_cancel(unicoap_scheduled_event_t* event);
153153
* messaging-layer state for transmissions. */
154154
#define UNICOAP_HAVE_MESSAGING_STATE \
155155
IS_USED(MODULE_UNICOAP_DRIVER_RFC7252_COMMON)
156+
/* MARK: unicoap_driver_extension_point */
156157

157158
/**
158159
* @brief A type used to retain state spanning across a single or multiple message exchanges

0 commit comments

Comments
 (0)