Skip to content

Commit

Permalink
Locking: Remove locking initialization from coap_new_context()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Jul 18, 2024
1 parent d87af11 commit f409463
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/coap_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ coap_new_context(const coap_address_t *listen_addr) {
}
memset(c, 0, sizeof(coap_context_t));

coap_lock_init();

This comment has been minimized.

Copy link
@safwansada

safwansada Jul 18, 2024

@mrdeep1 why this locking initialization is removed?

with earlier code was there any impact on coap server restart?

This comment has been minimized.

Copy link
@mrdeep1

mrdeep1 Jul 18, 2024

Author Collaborator

coap_startup() does this

#if COAP_THREAD_SAFE
  coap_lock_init();
#endif /* COAP_THREAD_SAFE */

The issue here is that if someone else has the global_lock locked, then if a different thread tries to create a new coap_context_t, then if this code is not removed, the global_lock will get trashed (reset) and the other thread is no-longer thread safe as well as potentially erroring out when global_lock is (twice) unlocked,

No impact whatsoever on your server restart issue.

coap_lock_lock(c, coap_free_type(COAP_CONTEXT, c); return NULL);
#ifdef COAP_EPOLL_SUPPORT
c->epfd = epoll_create1(0);
Expand Down

0 comments on commit f409463

Please sign in to comment.