1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 <cezarsa@gmail.com>
This commit is contained in:
Cezar Sa Espinola 2015-09-04 14:30:14 -03:00
parent d9065fcdb5
commit e787296c75

View file

@ -57,8 +57,17 @@ func Trap(cleanup func()) {
// DumpStacks dumps the runtime stack. // DumpStacks dumps the runtime stack.
func DumpStacks() { func DumpStacks() {
buf := make([]byte, 16384) var (
buf = buf[:runtime.Stack(buf, true)] 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 // 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. // traces won't show up in the log.
logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf) logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)