data race

A bug where two goroutines access the same memory at the same time and at least one of them writes, without any synchronization.

Races silently corrupt data or crash only under production load, and can break security checks that assume consistent state.

In more detail

The result depends on timing, so it can pass every test and still corrupt data in production. Prevent it by giving data a single owner, passing values between workers or protecting shared state with a lock. Tools such as Go's race detector find races that occur while tests run.

Example

go test -race ./...

Related terms

Taught in

References