---
source: https://iinventedlight.com/library/notes/go-race-detector.md
title: "Go race detector"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (go.dev text); prose restates cited source lines"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Go"
tags: ['go', 'concurrency', 'testing', 'race-detector']
sources:
  - id: S1
    title: "Data Race Detector - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/doc/articles/race_detector
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
  - id: S2
    title: "Introducing the Go Race Detector - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/blog/race-detector
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
---
# 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

```bash
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).
