Просмотр исходного кода

control/controlclient: grow goroutine debug buffer as needed

To not allocate 1MB up front on iOS.

Signed-off-by: Brad Fitzpatrick <[email protected]>
Brad Fitzpatrick 4 лет назад
Родитель
Сommit
4a2c3e2a0a
1 измененных файлов с 11 добавлено и 2 удалено
  1. 11 2
      control/controlclient/debug.go

+ 11 - 2
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)
 }