]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: debug: fix possible hang when multiple threads dump at once
authorWilly Tarreau <w@1wt.eu>
Wed, 13 Jul 2022 06:59:39 +0000 (08:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 13 Jul 2022 07:03:02 +0000 (09:03 +0200)
A bug in the thread dumper was introduced by commit 00c27b50c ("MEDIUM:
debug: make the thread dumper not rely on a thread mask anymore"). If
two or more threads try to trigger a thread dump exactly at the same
time, the second one may loop indefinitely trying to set the value to 1
while the other ones will wait for it to finish dumping before leaving.
This is a consequence of a logic change using thread numbers instead of
a thread mask, as threads do not need to see all other ones there anymore.

No backport is needed, this is only for 2.7.

src/debug.c

index 8d6210828ff7009da4319f2b615c2b31b7931396..b793e3ec03132c6486c0ddf8b6051869ab737816 100644 (file)
@@ -1313,12 +1313,11 @@ void ha_thread_dump_all_to_trash()
 {
        unsigned int old;
 
-       while (1) {
-               old = 0;
-               if (HA_ATOMIC_CAS(&thread_dump_state, &old, 1))
-                       break;
-               ha_thread_relax();
-       }
+       /* initiate a dump starting from first thread. Use a CAS
+        * so that we don't wait if we're not the first one.
+        */
+       old = 0;
+       HA_ATOMIC_CAS(&thread_dump_state, &old, 1);
 
        thread_dump_buffer = &trash;
        thread_dump_tid = tid;