]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: mark oneself harmless while waiting for threads to finish
authorWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 15:19:14 +0000 (17:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 17:26:35 +0000 (19:26 +0200)
The debug_handler() function waits for other threads to join, but does
not mark itself as harmless, so if at the same time another thread tries
to isolate, this may deadlock. In practice this does not happen as the
signal is received during epoll_wait() hence under harmless mode, but
it can possibly arrive under other conditions.

In order to improve this, while waiting for other threads to join, we're
now marking the current thread as harmless, as it's doing nothing but
waiting for the other ones. This way another harmless waiter will be able
to proceed. It's valid to do this since we're not doing anything else in
this loop.

One improvement could be to also check for the thread being idle and
marking it idle in addition to harmless, so that it can even release a
full isolation requester. But that really doesn't look worth it.

src/debug.c

index 3abcc0f00bf09e3714b3ae3698b1d2029e984997..39a6e02313a37261ba8f5b485e90d3d9425d10fa 100644 (file)
@@ -1340,9 +1340,15 @@ void debug_handler(int sig, siginfo_t *si, void *arg)
         */
 
        /* wait for all previous threads to finish first */
+       if (!harmless)
+               thread_harmless_now();
+
        while (threads_to_dump & (tid_bit - 1))
                ha_thread_relax();
 
+       if (!harmless)
+               thread_harmless_end();
+
        /* dump if needed */
        if (threads_to_dump & tid_bit) {
                if (thread_dump_buffer)
@@ -1361,8 +1367,15 @@ void debug_handler(int sig, siginfo_t *si, void *arg)
         * present again. This way the threads_to_dump variable never passes to
         * zero until all visitors have stopped waiting.
         */
+       if (!harmless)
+               thread_harmless_now();
+
        while (!(threads_to_dump & tid_bit))
                ha_thread_relax();
+
+       if (!harmless)
+               thread_harmless_end();
+
        HA_ATOMIC_AND(&threads_to_dump, ~tid_bit);
 
        /* mark the current thread as stuck to detect it upon next invocation