control/controlclient: grow goroutine debug buffer as needed

To not allocate 1MB up front on iOS.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/2496/head
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent 1986d071c3
commit 4a2c3e2a0a

@ -44,8 +44,17 @@ func dumpGoroutinesToURL(c *http.Client, targetURL string) {
// scrubbedGoroutineDump returns the list of all current goroutines, but with the actual // scrubbedGoroutineDump returns the list of all current goroutines, but with the actual
// values of arguments scrubbed out, lest it contain some private key material. // values of arguments scrubbed out, lest it contain some private key material.
func scrubbedGoroutineDump() []byte { func scrubbedGoroutineDump() []byte {
buf := make([]byte, 1<<20) var buf []byte
buf = buf[:runtime.Stack(buf, true)] // 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) return scrubHex(buf)
} }

Loading…
Cancel
Save