From 350501ea4d96e79053f08f51ee694f6ba73b6be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Villac=C3=ADs=20Lasso?= Date: Mon, 21 Feb 2022 18:08:13 -0500 Subject: [PATCH] Prevent deadlock between DNS resolution callback and LWIP call Stop taking the _asyncsock_mutex when DNS resolution has finished. Doing so causes a deadlock because the callback runs in the LWIP thread and therefore will wait forever on the _asyncsock_mutex lock, but the task holding the lock can in turn attempt a LWIP call, which requires the LWIP thread to be runnable. --- src/AsyncTCP.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index f38e42c..345fa3a 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -593,9 +593,9 @@ void _tcpsock_dns_found(const char * name, struct ip_addr * ipaddr, void * arg) } // Updating state visible to asyncTcpSock task - xSemaphoreTakeRecursive(_asyncsock_mutex, (TickType_t)portMAX_DELAY); + // MUST NOT take _asyncsock_mutex lock, risks a deadlock if task holding lock + // attempts a LWIP network call. c->_isdnsfinished = true; - xSemaphoreGiveRecursive(_asyncsock_mutex); // TODO: actually use name }