This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8c2f25343b1427a24c1ad87c3da2d60d1c02fbba Author: Marco Casaroli <[email protected]> AuthorDate: Fri Nov 6 11:03:23 2026 +0100 net/local: Do not take the lock twice when a listener closes. connect() of a local stream socket returns before accept(). When the listening socket closes with such a connection in its queue, local_release() calls local_subref() for the connection with the lock held. local_subref() calls local_release() for the connection, which takes the lock again. With assertions on, the mutex assertion ends the program. With assertions off, the thread waits for itself. In both cases the lock of all local sockets stays held. Take the connection from the queue with the lock held, and release it without the lock. A connection that comes during this time goes into the queue, and the loop takes it too. The behavior is the same in all build modes. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- net/local/local_release.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/local/local_release.c b/net/local/local_release.c index 564eef0309d..8390a546ad7 100644 --- a/net/local/local_release.c +++ b/net/local/local_release.c @@ -75,17 +75,21 @@ int local_release(FAR struct local_conn_s *conn) { FAR struct local_conn_s *accept; FAR dq_entry_t *waiter; - FAR dq_entry_t *tmp; DEBUGASSERT(conn->lc_proto == SOCK_STREAM); - /* Are there still clients waiting for a connection to the server? */ + /* Are there still clients waiting for a connection to the server? + * local_subref() can come back to this function for the accept + * connection, and that call takes the lock. + */ - dq_for_every_safe(&conn->u.server.lc_waiters, waiter, tmp) + while ((waiter = dq_remfirst(&conn->u.server.lc_waiters)) != NULL) { accept = container_of(waiter, struct local_conn_s, u.accept.lc_waiter); + local_unlock(); local_subref(accept); + local_lock(); } conn->u.server.lc_pending = 0;
