https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/sync/pool.go;l=213能看下 5w 个 goroutinues 卡住的应该有两种类型:
1. 第一种是 allPoolsMu.Lock() 卡住了。
2. 第二种就是持有锁的那个 goroutine 了,可以搜下 pinSlow 所有的 gouroutine ,是否有不同于 allPoolsMu.Lock() 的。再顺着这个 goroutine ,看它为什么卡住
func (p *Pool) pinSlow() (*poolLocal, int) {
// Retry under the mutex.
// Can not lock the mutex while pinned.
runtime_procUnpin()
allPoolsMu.Lock()
defer allPoolsMu.Unlock()
pid := runtime_procPin()
// poolCleanup won't be called while we are pinned.
s := p.localSize
l := p.local
if uintptr(pid) < s {
return indexLocal(l, pid), pid
}
if p.local == nil {
allPools = append(allPools, p)
}
// If GOMAXPROCS changes between GCs, we re-allocate the array and lose the old one.
size := runtime.GOMAXPROCS(0)
local := make([]poolLocal, size)
atomic.StorePointer(&p.local, unsafe.Pointer(&local[0])) // store-release
runtime_StoreReluintptr(&p.localSize, uintptr(size)) // store-release
return &local[pid], pid
}