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
- race detector — A checking mode, turned on with -race, that makes a Go program report when two goroutines touch the same memory unsafely.
- mutex — A lock that lets only one piece of code at a time run a critical section or do a particular piece of work.
- channel — A typed pipe in Go that one goroutine sends values into and another receives them from, safely handing data between them.
- goroutine — A function running concurrently with the rest of a Go program, started by putting the go keyword before a call.
- race condition — A bug whose outcome depends on the timing of two things happening at once.
Taught in
- Goroutines and Concurrent Execution — Concurrent Systems Programming with Go