From 3619605574d0c624513a10ecd543cc2bc1608f7b Mon Sep 17 00:00:00 2001 From: yinbin Date: Fri, 24 Jan 2025 14:18:26 +0800 Subject: [PATCH] Protocal: fixing deathlock between protocol threads and app thread --- src/lstack/core/lstack_lwip.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c index 648da58..3bb943f 100644 --- a/src/lstack/core/lstack_lwip.c +++ b/src/lstack/core/lstack_lwip.c @@ -267,7 +267,14 @@ struct pbuf *do_lwip_alloc_pbuf(pbuf_layer layer, uint16_t length, pbuf_type typ static inline bool pbuf_allow_append(struct pbuf *pbuf, uint16_t remain_size) { - pthread_spin_lock(&pbuf->pbuf_lock); + int ret; + + /* Using pthread_spin_trylock to avoid deadlock between app thread and lstack threads */ + ret = pthread_spin_trylock(&pbuf->pbuf_lock); + if (ret != 0) { + return false; + } + if (pbuf->tot_len > remain_size) { pthread_spin_unlock(&pbuf->pbuf_lock); return false; -- 2.33.0