go
runtime_error
ai_generated
true
WARNING: DATA RACE Write at 0x... by goroutine 7: main.main.func1() /main.go:12 +0x... Previous read at 0x... by main goroutine: main.main() /main.go:9 +0x...
ID: go/race-detector-detected
80%Fix Rate
89%Confidence
0Evidence
2024-03-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
The race detector (-race) found unsynchronized access to shared memory between goroutines.
generic中文
race 检测器(-race)发现 goroutine 之间对共享内存的未同步访问。
Workarounds
-
95% success
var mu sync.Mutex mu.Lock() counter++ mu.Unlock()
-
90% success
results := make(chan int, 1) go func() { results <- compute() }() v := <-results
Dead Ends
Common approaches that don't work:
-
95% fail
Hides the bug; production will still corrupt data.
-
90% fail
Reduces but does not eliminate race; detector still flags it.