
Warning Data Race Detected in go test and How to Fix It
Fix WARNING: DATA RACE from go test -race. Read the report, find the two accesses and the goroutine that started them, and choose a mutex, channel or atomic.
Tag
5 articles

Fix WARNING: DATA RACE from go test -race. Read the report, find the two accesses and the goroutine that started them, and choose a mutex, channel or atomic.

Run go test -race locally and in CI: read a data race report, see the lost updates it explains, use GORACE options, and plan for the extra time and memory.

What a data race is in Go, with examples you can run: lost counter updates, vanished appends, inconsistent reads, and the three ways to remove each race.

The usual excuses for a harmless data race in Go, tested: torn slice reads you can reproduce, a compiler that deletes your store, and double-checked locking.

Turn on the Go race detector, read a report line by line, fix what it finds, measure its cost and learn what it cannot see, with CI and GORACE settings.