Take Containerd as an example. The current way of printing the stack may be unsafe. Containerd print stack function: ``` func dumpStacks(writeToFile bool) { 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] logrus.Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
if writeToFile { // Also write to file to aid gathering diagnostics name := filepath.Join(os.TempDir(), fmt.Sprintf("containerd.%d.stacks.log", os.Getpid())) f, err := os.Create(name) if err != nil { return } defer f.Close() f.WriteString(string(buf)) logrus.Infof("goroutine stack dump written to %s", name) } } ``` In a production environment, containerd will be stuck due to some requests, resulting in hundreds of thousands of Goroutines. If you dump all the Goroutine stacks, it may consume several gigabytes of memory. In addition, the log function may enlarge the memory (maybe double the original size, or more). Can Golang provide stack output of slices? For example, using Goroutine as the granularity is a good choice. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/bd33d380-5815-4b3f-905a-fe08aceda3e8n%40googlegroups.com.