Skip to content

proposal: runtime: add a default, non-destructive signal handler that creates a stack dump #64687

@kgibm

Description

@kgibm

Proposal Details

By default, Go produces a stack dump and exits on various signals:

A SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGSTKFLT, SIGEMT, or SIGSYS signal causes the program to exit with a stack dump.

It is commonly desired to create such a stack dump using a mechanism such as a signal but without exiting. Such thread dumps may be used to investigate hangs or as a rudimentary sampling profiler. Such built-in handlers are common in other languages such as Java (e.g. using SIGQUIT).

One way for a program to handle this requirement is to handle a signal such as SIGUSR1, generate a stack dump by calling pprof.Lookup on the goroutine profile and then write that to a file with Profile.WriteTo.

Alternatively, native debuggers and tools such as pstack may be used but they generally lack the detail of Go stack dumps.

This proposal is for Go to have a built-in signal handler that non-destructively writes a thread dump to stderr in response to a signal such as SIGUSR2. This would be a behavior change that may cause unintended side effects for any programs that already have a SIGUSR2 handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions