···44package process
5566import (
77+ "bytes"
78 "fmt"
88- "io"
99 "runtime/pprof"
1010 "sort"
1111 "time"
···175175 // Now from within the lock we need to get the goroutines.
176176 // Why? If we release the lock then between between filling the above map and getting
177177 // the stacktraces another process could be created which would then look like a dead process below
178178- reader, writer := io.Pipe()
179179- defer reader.Close()
180180- go func() {
181181- err := pprof.Lookup("goroutine").WriteTo(writer, 0)
182182- _ = writer.CloseWithError(err)
183183- }()
184184- stacks, err = profile.Parse(reader)
178178+ var buf bytes.Buffer
179179+ if err := pprof.Lookup("goroutine").WriteTo(&buf, 0); err != nil {
180180+ return nil, 0, 0, err
181181+ }
182182+183183+ stacks, err = profile.ParseData(buf.Bytes())
185184 if err != nil {
186185 return nil, 0, 0, err
187186 }