go
runtime_error
ai_generated
true
fatal error: concurrent map writes
ID: go/data-race-map-concurrent-write
80%Fix Rate
89%Confidence
0Evidence
2024-04-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.16 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
Two goroutines write to the same map without synchronization. The runtime detects concurrent writes and aborts the process.
generic中文
两个 goroutine 在无同步的情况下写入同一个 map。运行时检测到并发写并中止进程。
Workarounds
-
92% success
var m sync.Map m.Store(k, v) v, ok := m.Load(k)
-
96% success
var mu sync.RWMutex mu.Lock() m[k] = v mu.Unlock()
Dead Ends
Common approaches that don't work:
-
90% fail
Other writes still race; the runtime aborts on the first detected concurrent pair.
-
85% fail
Sleeps don't eliminate races under real load; the crash just becomes intermittent.