]> git.kaiwu.me - haproxy.git/commit
BUG/MEDIUM: fd: Fix a deadlock when closing other tgroups fds
authorOlivier Houchard <ohouchard@haproxy.com>
Mon, 6 Jul 2026 13:36:08 +0000 (15:36 +0200)
committerOlivier Houchard <cognet@ci0.org>
Mon, 6 Jul 2026 14:03:58 +0000 (16:03 +0200)
commit753aa44416f705fb16a957a1323e6090c2fcf165
treeebd528a729b43a5815d036ad13b376cbbfc73da6
parent73a4f6bea70d4035dd2f5c4ec6d65f3b749a08b0
BUG/MEDIUM: fd: Fix a deadlock when closing other tgroups fds

Commit 061754b249b9903913d6766c1ab31bb393ee5c0d attempted to make it
possible to close file descriptors belonging to other thread groups by
using thread isolation.
The problem is, closing other thread groups' fds usually happens when we
destroy a listener, in which case we hold the listener lock. If any
other thread tries to get that lock while we're waiting for the thread
isolation, then they will deadlock.
This can happen with any type of listener, but it is easier to reproduce
with a suspend/resume loop with ABNS sockets, as a suspend translates to
a close here.
To fix that, instead of using thread isolation, do something similar to
what's done when the fd belongs to our thread group. Increase the tgid
ref counter, so that we're sure nobody will close the fd while we're
dealing with it, then set the FD_MUST_CLOSE bit and set thread_mask to
0.
At this point, if no thread was running on that fd, no one will and we
can safely close it. So just call _fd_delete_orphan() if the
running_mask is 0 and if the FD_MUST_CLOSE bit is still there, otherwise
we can safely assume another thread will take care of it.

This should be backported up to 2.8.
src/fd.c