]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: make ha_stuck_warning() only work for the current thread
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Apr 2025 06:54:43 +0000 (08:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Apr 2025 14:25:47 +0000 (16:25 +0200)
Since we no longer call it with a foreign thread, let's simplify its code
and get rid of the special cases that were relying on ha_thread_dump_fill()
and synchronization with a remote thread. We're not only dumping the
current thread so ha_thread_dump_one() is sufficient.

include/haproxy/debug.h
src/debug.c
src/wdt.c

index bdadf0cbd57bf2c1128f681db6140b9a0822d8ee..7f6458c9c5775fc52808a85394c3357619b747c5 100644 (file)
@@ -32,7 +32,7 @@ void ha_thread_dump_one(struct buffer *buf, int is_caller);
 void ha_dump_backtrace(struct buffer *buf, const char *prefix, int dump);
 void ha_backtrace_to_stderr(void);
 void ha_panic(void);
-void ha_stuck_warning(int thr);
+void ha_stuck_warning(void);
 
 void post_mortem_add_component(const char *name, const char *version,
                               const char *toolchain, const char *toolchain_opts,
index 2816c3f44f3f13a794a156e5b090867eb2fc5b55..aa2b473887663bae9f11c4b5aca54f8f655e60ff 100644 (file)
@@ -804,8 +804,11 @@ void ha_panic()
 
 /* Dumps a state of the current thread on fd #2 and returns. It takes a great
  * care about not using any global state variable so as to gracefully recover.
+ * It is designed to be called exclusively from the watchdog signal handler,
+ * and takes care of not touching thread_dump_buffer so as not to interfere
+ * with any other parallel dump that could have been started.
  */
-void ha_stuck_warning(int thr)
+void ha_stuck_warning(void)
 {
        char msg_buf[4096];
        struct buffer buf;
@@ -824,8 +827,8 @@ void ha_stuck_warning(int thr)
 
        buf = b_make(msg_buf, sizeof(msg_buf), 0, 0);
 
-       p = HA_ATOMIC_LOAD(&ha_thread_ctx[thr].prev_cpu_time);
-       n = now_cpu_time_thread(thr);
+       p = HA_ATOMIC_LOAD(&th_ctx->prev_cpu_time);
+       n = now_cpu_time();
 
        chunk_printf(&buf,
                     "\nWARNING! thread %u has stopped processing traffic for %llu milliseconds\n"
@@ -839,18 +842,14 @@ void ha_stuck_warning(int thr)
                     "    blocking delay before emitting this warning may be adjusted via the global\n"
                     "    'warn-blocked-traffic-after' directive. Please check the trace below for\n"
                     "    any clues about configuration elements that need to be corrected:\n\n",
-                    thr + 1, (n - p) / 1000000ULL,
-                    HA_ATOMIC_LOAD(&ha_thread_ctx[thr].stream_cnt));
+                    tid + 1, (n - p) / 1000000ULL,
+                    HA_ATOMIC_LOAD(&ha_thread_ctx[tid].stream_cnt));
 
        DISGUISE(write(2, buf.area, buf.data));
 
-       /* Note below: the target thread will dump itself */
        chunk_reset(&buf);
-       if (ha_thread_dump_fill(&buf, thr)) {
-               DISGUISE(write(2, buf.area, buf.data));
-               /* restore the thread's dump pointer for easier post-mortem analysis */
-               ha_thread_dump_done(thr);
-       }
+       ha_thread_dump_one(&buf, 1);
+       DISGUISE(write(2, buf.area, buf.data));
 
 #ifdef USE_LUA
        if (get_tainted() & TAINTED_LUA_STUCK_SHARED && global.nbthread > 1) {
index dc33f9621c82dd25cdb75f5ad616880657ab0a95..fa600d6fab0150ddb44535507460ce4881e2fef3 100644 (file)
--- a/src/wdt.c
+++ b/src/wdt.c
@@ -191,7 +191,7 @@ void wdt_handler(int sig, siginfo_t *si, void *arg)
        curr_ctxsw = activity[tid].ctxsw;
 
        if (curr_ctxsw == prev_ctxsw)
-               ha_stuck_warning(tid);
+               ha_stuck_warning();
        else
                per_thread_wd_ctx[tid].prev_ctxsw = curr_ctxsw;
        /* let's go on */