go runtime_error ai_generated true

WARNING: DATA RACE Write at 0x00c0000b4010 by goroutine 7: main.increment() /app/main.go:12 +0x44

ID: go/data-race-detected-by-race-detector

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-03-30First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.18 active — — —
1.21 active — — —
1.22 active — — —

Root Cause

The race detector observed unsynchronized concurrent access to the same memory. Common with shared counters, slices, or struct fields accessed from multiple goroutines.

generic

中文

竞态检测器观察到对同一内存的未同步并发访问。常见于多 goroutine 访问的共享计数器、slice 或结构体字段。

Workarounds

  1. 97% success
    var mu sync.Mutex
    func inc() {
        mu.Lock()
        counter++
        mu.Unlock()
    }
  2. 95% success
    var counter int64
    atomic.AddInt64(&counter, 1)

Dead Ends

Common approaches that don't work:

  1. 95% fail

    The bug still exists; you just stop seeing reports while corrupt data and crashes continue.

  2. 90% fail

    Yielding does not provide memory ordering or mutual exclusion; races remain.