go
runtime_error
ai_generated
true
fatal error: all goroutines are asleep - deadlock! (sync.Once.Do calling itself)
ID: go/sync-once-deadlock-recursive
80%Fix Rate
86%Confidence
0Evidence
2024-06-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
A sync.Once.Do function calls the same Once.Do again (directly or indirectly), blocking on its own mutex forever.
generic中文
sync.Once.Do 的函数再次(直接或间接)调用同一个 Once.Do,永久阻塞在自己的互斥锁上。
Workarounds
-
95% success
Ensure the function passed to Do never calls the same Once; extract shared init into a separate helper
-
88% success
Use sync.OnceFunc/OnceValue (Go 1.21+) and keep init logic non-reentrant
Dead Ends
Common approaches that don't work:
-
90% fail
Once holds an internal mutex with no timeout support; deadlock persists
-
80% fail
Loses thread-safety; introduces data races