go runtime_error ai_generated true

fatal error: concurrent map writes

ID: go/concurrent-map-write

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-01-19First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 93% success
    var mu sync.Mutex
    mu.Lock()
    m[k] = v
    mu.Unlock()
  2. 85% success
    var m sync.Map
    m.Store(k, v)
    v, ok := m.Load(k)

Dead Ends

Common approaches that don't work:

  1. 99% fail

    fatal error is not a panic; recover cannot catch it.

  2. 90% fail

    Worsens the race by running more goroutines in parallel.