← All notes

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

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

Sources

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

Permanent ID: iil:note:hx1fm6ve

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.},
}

Markdown

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.