Go race detector
Answer: Go's race detector finds data races at run time: two goroutines accessing the same variable concurrently with at least one write. Enable it by adding -race to go test, go run or go build; when it finds a race it prints stack traces of the conflicting accesses.
Use it
go test -race ./...
go run -race main.go
go build -race ./cmd/app
What a report shows
- Stacks for the conflicting read and write.
- Stacks where the involved goroutines were created.
Limits
Race-enabled binaries use more CPU and memory, so they are usually not shipped to production.
Background
The detector is based on the ThreadSanitizer runtime library and was integrated into Go in September 2012.
Claims
- id: C1 claim: A data race is concurrent access with at least one write. source: S1 evidence: "A data race occurs when two goroutines access the same variable concurrently and at least"
- id: C2 claim: To use it, add the -race flag. source: S1 evidence: "To use it, add the -race flag to the go command:"
- id: C3 claim: Reports contain stack traces for conflicting accesses. source: S1 evidence: "The report contains stack traces for conflicting accesses"
- id: C4 claim: The technology was integrated with Go in September 2012. source: S2 evidence: "The technology was integrated with Go in September 2012; since then it has detected"
Sources
- [S1] Data Race Detector - The Go Programming Language. The Go Authors (go.dev). https://go.dev/doc/articles/race_detector . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
- [S2] Introducing the Go Race Detector - The Go Programming Language. The Go Authors (go.dev). https://go.dev/blog/race-detector . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors (go.dev), Data Race Detector - The Go Programming Language, CC BY 4.0 (go.dev text); The Go Authors (go.dev), Introducing the Go Race Detector - The Go Programming Language, CC BY 4.0 (go.dev text).
Cite this
iinventedlight. 2026. "Go race detector." iinventedlight Library, iil:note:hx1fm6ve, version of 2026-11-04. https://iinventedlight.com/library/notes/go-race-detector/. License: CC-BY-4.0.
@misc{iil_note_hx1fm6ve,
author = {{iinventedlight}},
title = {{Go race detector}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/go-race-detector/},
note = {Permanent ID iil:note:hx1fm6ve. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/go-race-detector.md.