From: Willy Tarreau Date: Thu, 17 Apr 2025 06:54:43 +0000 (+0200) Subject: MINOR: debug: make ha_stuck_warning() only work for the current thread X-Git-Tag: v3.2-dev11~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c16d5415a807f5a46d34ee6aac4c35fd42dac0c0;p=thirdparty%2Fhaproxy.git MINOR: debug: make ha_stuck_warning() only work for the current thread 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. --- diff --git a/include/haproxy/debug.h b/include/haproxy/debug.h index bdadf0cbd..7f6458c9c 100644 --- a/include/haproxy/debug.h +++ b/include/haproxy/debug.h @@ -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, diff --git a/src/debug.c b/src/debug.c index 2816c3f44..aa2b47388 100644 --- a/src/debug.c +++ b/src/debug.c @@ -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) { diff --git a/src/wdt.c b/src/wdt.c index dc33f9621..fa600d6fa 100644 --- 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 */