goroutine-leak

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

常见根因

修复

相关命令