From 7718d060ebddad9f5f85386582a1a9a449057d74 Mon Sep 17 00:00:00 2001 From: John Howard Date: Fri, 5 Apr 2019 12:36:03 -0700 Subject: [PATCH] Write stack dump to `os.TempDir()` as well Signed-off-by: John Howard --- cmd/containerd/command/main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/containerd/command/main.go b/cmd/containerd/command/main.go index 098a6f5a3..414a12da4 100644 --- a/cmd/containerd/command/main.go +++ b/cmd/containerd/command/main.go @@ -291,4 +291,14 @@ func dumpStacks() { } buf = buf[:stackSize] logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf) + + // Also write to file to aid gathering diagnostics + name := filepath.Join(os.TempDir(), fmt.Sprintf("containerd.%d.stacks.log", os.Getpid())) + f, err := os.Create(name) + if err != nil { + return + } + defer f.Close() + f.WriteString(string(buf)) + logrus.Infof("goroutine stack dump written to %s", name) }