go
runtime_error
ai_generated
true
fatal error: concurrent map writes
ID: go/concurrent-map-write
80%Fix Rate
90%Confidence
0Evidence
2024-01-19First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
Two or more goroutines write to the same map without synchronization; runtime detects write/write race and aborts.
generic中文
两个或更多 goroutine 未同步地写入同一 map;运行时检测到写/写竞争后中止。
Workarounds
-
93% success
var mu sync.Mutex mu.Lock() m[k] = v mu.Unlock()
-
85% success
var m sync.Map m.Store(k, v) v, ok := m.Load(k)
Dead Ends
Common approaches that don't work:
-
99% fail
fatal error is not a panic; recover cannot catch it.
-
90% fail
Worsens the race by running more goroutines in parallel.