Go goroutine 泄漏
Go 服务内存和 goroutine 数持续增长,最终 OOM 或调度变慢;/debug/pprof/goroutine 显示大量相同调用栈的 goroutine 阻塞在 channel、锁或网络读写。
curl -s http://localhost:6060/debug/pprof/goroutine?debug=1 | head -50
curl -s http://localhost:6060/debug/pprof/goroutine?debug=2 > goroutines.txt
go tool pprof http://localhost:6060/debug/pprof/goroutine
查看 goroutine 数和内存:
curl -s http://localhost:6060/debug/pprof/ | grep goroutine
go tool pprof -top http://localhost:6060/debug/pprof/heap
errgroup 或 WaitGroup 管理生命周期。Timeout 和 Transport 超时。go tool pprof — goroutine/heap/CPU 分析curl — 访问 pprof 端点go-torch / pprof — 火焰图netstat / ss — 连接堆积排查