Skip to content

Commit 0376dd4

Browse files
committed
Don't write dumped stacks to file for ETW capture state
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
1 parent a91e043 commit 0376dd4

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

cmd/containerd/command/main.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func setLevel(context *cli.Context, config *srvconfig.Config) error {
278278
return nil
279279
}
280280

281-
func dumpStacks() {
281+
func dumpStacks(writeToFile bool) {
282282
var (
283283
buf []byte
284284
stackSize int
@@ -292,13 +292,15 @@ func dumpStacks() {
292292
buf = buf[:stackSize]
293293
logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
294294

295-
// Also write to file to aid gathering diagnostics
296-
name := filepath.Join(os.TempDir(), fmt.Sprintf("containerd.%d.stacks.log", os.Getpid()))
297-
f, err := os.Create(name)
298-
if err != nil {
299-
return
295+
if writeToFile {
296+
// Also write to file to aid gathering diagnostics
297+
name := filepath.Join(os.TempDir(), fmt.Sprintf("containerd.%d.stacks.log", os.Getpid()))
298+
f, err := os.Create(name)
299+
if err != nil {
300+
return
301+
}
302+
defer f.Close()
303+
f.WriteString(string(buf))
304+
logrus.Infof("goroutine stack dump written to %s", name)
300305
}
301-
defer f.Close()
302-
f.WriteString(string(buf))
303-
logrus.Infof("goroutine stack dump written to %s", name)
304306
}

cmd/containerd/command/main_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func handleSignals(ctx context.Context, signals chan os.Signal, serverC chan *se
4848
log.G(ctx).WithField("signal", s).Debug("received signal")
4949
switch s {
5050
case unix.SIGUSR1:
51-
dumpStacks()
51+
dumpStacks(true)
5252
case unix.SIGPIPE:
5353
continue
5454
default:

cmd/containerd/command/main_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ func setupDumpStacks() {
8888
logrus.Debugf("Stackdump - waiting signal at %s", event)
8989
for {
9090
windows.WaitForSingleObject(h, windows.INFINITE)
91-
dumpStacks()
91+
dumpStacks(true)
9292
}
9393
}()
9494
}
9595

9696
func etwCallback(sourceID *guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) {
9797
if state == etw.ProviderStateCaptureState {
98-
dumpStacks()
98+
dumpStacks(false)
9999
}
100100
}
101101

0 commit comments

Comments
 (0)