From: Willy Tarreau Date: Wed, 24 Feb 2021 18:40:49 +0000 (+0100) Subject: BUG/MINOR: fd: properly wait for !running_mask in fd_set_running_excl() X-Git-Tag: v2.4-dev10~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5926e384e62d6e47272062f1fbec235bd11cc517;p=thirdparty%2Fhaproxy.git BUG/MINOR: fd: properly wait for !running_mask in fd_set_running_excl() In fd_set_running_excl() we don't reset the old mask in the CAS loop, so if we fail on the first round, we'll forcefully take the FD on the next one. In practice it's used bu fd_insert() and fd_delete() only, none of which is supposed to be passed an FD which is still in use since in practice, given that for now only listeners may be enabled on multiple threads at once. This can be backported to 2.2 but shouldn't result in fixing any user visible bug for now. --- diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h index c741eb39e6..20e4d754fa 100644 --- a/include/haproxy/fd.h +++ b/include/haproxy/fd.h @@ -343,7 +343,8 @@ static inline int fd_set_running(int fd) static inline void fd_set_running_excl(int fd) { unsigned long old_mask = 0; - while (!_HA_ATOMIC_CAS(&fdtab[fd].running_mask, &old_mask, tid_bit)); + while (!_HA_ATOMIC_CAS(&fdtab[fd].running_mask, &old_mask, tid_bit)) + old_mask = 0; }