]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: debug: on panic, make the target thread automatically allocate its buf
authorWilly Tarreau <w@1wt.eu>
Sat, 19 Oct 2024 12:53:11 +0000 (14:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 19 Oct 2024 14:01:52 +0000 (16:01 +0200)
commit278b9613a32ddb0b5ffa1d66e6c25f434758c65a
treef8ee0fbdfd3718957b6442d2001706e3ca7c453d
parentafeac4bc026e64e27d99e50480bff5bc1ee60cb9
MEDIUM: debug: on panic, make the target thread automatically allocate its buf

One main problem with panic dumps is that they're filling the dumping
thread's trash, and that the global thread_dump_buffer is too small to
catch enough of them.

Here we're proceeding differently. When dumping threads for a panic, we're
passing the magic value 0x2 as the buffer, and it will instruct the target
thread to allocate its own buffer using get_trash_chunk() (which is signal
safe), so that each thread dumps into its own buffer. Then the thread will
wait for the buffer to be consumed, and will assign its own thread_dump_buffer
to it. This way we can simply dump all threads' buffers from gdb like this:

  (gdb) set $t=0
        while ($t < global.nbthread)
          printf "%s\n", ha_thread_ctx[$t].thread_dump_buffer.area
          set $t=$t+1
        end

For now we make it wait forever since it's only called on panic and we
want to make sure the thread doesn't leave and continues to use that trash
buffer or do other nasty stuff. That way the dumping thread will make all
of them die.

This would be useful to backport to the most recent branches to help
troubleshooting. It backports well to 2.9, except for some trivial
context in tinfo-t.h for an updated comment. 2.8 and older would also
require TAINTED_PANIC. The following previous patches are required:

   MINOR: debug: make mark_tainted() return the previous value
   MINOR: chunk: drop the global thread_dump_buffer
   MINOR: debug: split ha_thread_dump() in two parts
   MINOR: debug: slightly change the thread_dump_pointer signification
   MINOR: debug: make ha_thread_dump_done() take the pointer to be used
   MINOR: debug: replace ha_thread_dump() with its two components
include/haproxy/tinfo-t.h
src/debug.c