go
runtime_error
ai_generated
true
panic: close of closed channel (in goroutine)
ID: go/goroutine-channel-close-race
80%Fix Rate
88%Confidence
0Evidence
2024-12-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
Root Cause
Two or more goroutines attempt to close the same channel without synchronization, causing a panic.
generic中文
两个或多个 goroutine 在没有同步的情况下尝试关闭同一个通道,导致恐慌。
Workarounds
-
95% success
Use sync.Once to ensure channel is closed only once.
-
90% success
Designate a single goroutine to own the channel and close it.
Dead Ends
Common approaches that don't work:
-
80% fail
Recovering doesn't solve the race; it masks the error but may leave other goroutines in inconsistent state.
-
90% fail
Flag check is racy; another goroutine may close it between check and close.