From 4a2c3e2a0a455feef94cbbf22c3a0688c596ae87 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 22 Jul 2021 12:32:08 -0700 Subject: [PATCH] control/controlclient: grow goroutine debug buffer as needed To not allocate 1MB up front on iOS. Signed-off-by: Brad Fitzpatrick --- control/controlclient/debug.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/control/controlclient/debug.go b/control/controlclient/debug.go index dc7e12c05..b14643f7a 100644 --- a/control/controlclient/debug.go +++ b/control/controlclient/debug.go @@ -44,8 +44,17 @@ func dumpGoroutinesToURL(c *http.Client, targetURL string) { // scrubbedGoroutineDump returns the list of all current goroutines, but with the actual // values of arguments scrubbed out, lest it contain some private key material. func scrubbedGoroutineDump() []byte { - buf := make([]byte, 1<<20) - buf = buf[:runtime.Stack(buf, true)] + var buf []byte + // Grab stacks multiple times into increasingly larger buffer sizes + // to minimize the risk that we blow past our iOS memory limit. + for size := 1 << 10; size <= 1<<20; size += 1 << 10 { + buf = make([]byte, size) + buf = buf[:runtime.Stack(buf, true)] + if len(buf) < size { + // It fit. + break + } + } return scrubHex(buf) }