From 0376dd4605abc1de4bf2db2bdbbf61007793f6ff Mon Sep 17 00:00:00 2001 From: Kevin Parsons Date: Thu, 18 Apr 2019 17:46:35 -0700 Subject: [PATCH] Don't write dumped stacks to file for ETW capture state Signed-off-by: Kevin Parsons --- cmd/containerd/command/main.go | 20 +++++++++++--------- cmd/containerd/command/main_unix.go | 2 +- cmd/containerd/command/main_windows.go | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cmd/containerd/command/main.go b/cmd/containerd/command/main.go index 414a12da4..f6321e51c 100644 --- a/cmd/containerd/command/main.go +++ b/cmd/containerd/command/main.go @@ -278,7 +278,7 @@ func setLevel(context *cli.Context, config *srvconfig.Config) error { return nil } -func dumpStacks() { +func dumpStacks(writeToFile bool) { var ( buf []byte stackSize int @@ -292,13 +292,15 @@ 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 + if writeToFile { + // 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) } - defer f.Close() - f.WriteString(string(buf)) - logrus.Infof("goroutine stack dump written to %s", name) } diff --git a/cmd/containerd/command/main_unix.go b/cmd/containerd/command/main_unix.go index dc3f11b78..90de40eaa 100644 --- a/cmd/containerd/command/main_unix.go +++ b/cmd/containerd/command/main_unix.go @@ -48,7 +48,7 @@ func handleSignals(ctx context.Context, signals chan os.Signal, serverC chan *se log.G(ctx).WithField("signal", s).Debug("received signal") switch s { case unix.SIGUSR1: - dumpStacks() + dumpStacks(true) case unix.SIGPIPE: continue default: diff --git a/cmd/containerd/command/main_windows.go b/cmd/containerd/command/main_windows.go index 3aa44c892..da126cac5 100644 --- a/cmd/containerd/command/main_windows.go +++ b/cmd/containerd/command/main_windows.go @@ -88,14 +88,14 @@ func setupDumpStacks() { logrus.Debugf("Stackdump - waiting signal at %s", event) for { windows.WaitForSingleObject(h, windows.INFINITE) - dumpStacks() + dumpStacks(true) } }() } func etwCallback(sourceID *guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) { if state == etw.ProviderStateCaptureState { - dumpStacks() + dumpStacks(false) } }