From e787296c75c15d1a4d32474432f674d6d58ee4c1 Mon Sep 17 00:00:00 2001 From: Cezar Sa Espinola Date: Fri, 4 Sep 2015 14:30:14 -0300 Subject: [PATCH] Ensure goroutines dump is not truncated Calling runtime.Stack requires the buffer to be big enough to fit the goroutines dump. If it's not big enough the dump will be truncated and the value returned will be the same size as the buffer. The code was changed to handle this situation and try again with a bigger buffer. Each time the dump doesn't fit in the buffer its size is doubled. Signed-off-by: Cezar Sa Espinola --- pkg/signal/trap.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/signal/trap.go b/pkg/signal/trap.go index 80b5e871f3..2cf5ccf0d2 100644 --- a/pkg/signal/trap.go +++ b/pkg/signal/trap.go @@ -57,8 +57,17 @@ func Trap(cleanup func()) { // DumpStacks dumps the runtime stack. func DumpStacks() { - buf := make([]byte, 16384) - buf = buf[:runtime.Stack(buf, true)] + var ( + buf []byte + stackSize int + ) + bufferLen := 16384 + for stackSize == len(buf) { + buf = make([]byte, bufferLen) + stackSize = runtime.Stack(buf, true) + bufferLen *= 2 + } + buf = buf[:stackSize] // Note that if the daemon is started with a less-verbose log-level than "info" (the default), the goroutine // traces won't show up in the log. logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)