Documentation
¶
Overview ¶
Package stackdump writes every goroutine's stack to a file in the K-brain log directory, without stopping the process, so a frozen kn or kn backend can be diagnosed: on SIGUSR1 (Unix), on GET /v1/debug/stacks (backend), and automatically when a watchdog sees the UI loop or the backend stall.
Index ¶
Constants ¶
const Prefix = "stacks-"
Prefix starts every dump file name: stacks-<timestamp>-<pid>.txt.
const SignalSupported = true
SignalSupported reports whether OnSignal can dump on a signal here.
Variables ¶
This section is empty.
Functions ¶
func OnSignal ¶
OnSignal writes a dump each time the process receives SIGUSR1 and calls report with the outcome (report may be nil). The process keeps running. The returned function stops listening.
Types ¶
type Watchdog ¶
type Watchdog struct {
Name string
Interval time.Duration
Timeout time.Duration
// Probe returns once the watched loop or lock has made progress. It must
// return when ctx is cancelled.
Probe func(ctx context.Context)
// Paused, when set, reports a state in which the watched loop is blocked
// on purpose (an external editor in the foreground); time spent paused
// does not count.
Paused func() bool
// MaxDumps bounds the dumps per process; 0 means 3.
MaxDumps int
// OnStall is called after a stall's dump with its outcome (tests, logs).
OnStall func(path string, err error)
// Write writes the dump; nil uses stackdump.Write.
Write func(reason string) (string, error)
}
Watchdog runs Probe every Interval. When a probe has not returned after Timeout, it writes one dump for that stall and logs a warning; the next stall, after a probe has returned again, may dump again, up to MaxDumps.