代码案例
package main
import (
"fmt"
"net/http"
_ "net/http/pprof"
)
func main(){
for i := 0; i < 5; i++ {
go func() {
select {
default:
return
}
}()
}
go func() { select {} }() // 泄漏协程
if err := http.ListenAndServe(":8080", nil); err != nil {
fmt.Println("start pprof failed")
}
}
web查看协程泄漏信息
http://127.0.0.1:8080/debug/pprof/goroutine?debug=2
http://127.0.0.1:8080/debug/pprof/goroutine?debug=1