go runtime_error ai_generated true

WARNING: DATA RACE

ID: go/race-detector-found-data-race

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

Version Compatibility

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

Root Cause

The race detector (go test -race / go run -race) observed two goroutines accessing the same memory location concurrently, at least one being a write, without synchronization.

generic

中文

竞态检测器(go test -race / go run -race)观察到两个 goroutine 并发访问同一内存位置,至少一个是写操作,且没有同步。

Workarounds

  1. 92% success
    Introduce sync.Mutex or sync/atomic around the shared variable; ensure happens-before via channel send/receive.
  2. 88% success
    Pass data by value into goroutines or use immutable snapshots; run go test -race in CI to prevent regressions.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    The race still corrupts data in production; hiding it makes failures nondeterministic and worse.

  2. 90% fail

    Sleeps reduce detection probability but do not establish a happens-before relationship.