Skip to content

proposal: runtime: (optionally) print M backtrace on crash #67929

Closed as not planned
@aktau

Description

@aktau

Proposal Details

Currently, when crashing due to receiving a fatal signal (e.g.: SIGABRT), Go outputs backtraces for all Gs, and then the registers of the thread on which the signal hit:

level, _, docrash := gotraceback()
if level > 0 {
goroutineheader(gp)
tracebacktrap(c.sigpc(), c.sigsp(), c.siglr(), gp)
if crashing.Load() > 0 && gp != mp.curg && mp.curg != nil && readgstatus(mp.curg)&^_Gscan == _Grunning {
// tracebackothers on original m skipped this one; trace it now.
goroutineheader(mp.curg)
traceback(^uintptr(0), ^uintptr(0), 0, mp.curg)
} else if crashing.Load() == 0 {
tracebackothers(gp)
print("\n")
}
dumpregs(c)
}
.

We're observing an issue where a Go program appears to stall (making no significant progress, if any) that we have only seen in production. We have not been able to reproduce at will. The G backtraces indicate that there are many (1000s) runnable goroutines when this happens, yet only 3 out of ~10 GOMAXPROCS Ms appear assigned to a goroutine. It is unclear what the other Ms are doing. Seeing where they are may provide a hint as to what's going wrong.

I believe this to be useful in general, although in an otherwise healthy process I'd expect at least the GOMAXPROCS Ms to be mentioned in goroutine backtraces like this:

goroutine 45890 gp=0xc00fa35340 m=15 mp=0xc007a35808 [running]:

But that would still leave the Ms that are in cgo-calls or syscalls.

Regrettably, we have not been able to extract a coredump from such a crash from our environment, which would be another way of getting at this useful information.

It's fine if this functionality is hidden behind a GODEBUG flag, but I'd say there's a case for enabling it by default. The format (header) would have to be somewhat different from regular goroutine stacks, as otherwise tools parsing this may get confused.

cc @mknyszek @prattmic

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions