WARNING: DATA RACE Go Origin: Application & API Last updated 4 Nov 2026

Go: WARNING: DATA RACE — Write at 0x00c0000 by goroutine 7: / Previous read at ... by goroutine 6

The race detector (-race) observed two goroutines accessing the same memory concurrently with at least one write and no synchronisation.

Exact message you may see WARNING: DATA RACEWARNING: DATA RACE Write at by goroutinePrevious read at by goroutinetesting.go: race detected during execution of testFound 1 data race(s)
Seen on: Go

Meaning

The report lists the conflicting accesses with stack traces and where the goroutines were created. Fix by synchronising (mutex, channel, atomic) or removing shared mutable state. Loop variable capture in closures is a classic source (fixed per-iteration in Go 1.22).

Common causes

  • Shared variable without mutex
  • Closure capturing a loop variable (Go < 1.22)
  • Concurrent map/slice access
  • Unsynchronised counters (use sync/atomic)
  • Global state mutated by handlers

⚡ Quick fix

  1. Protect shared data with sync.Mutex or use channels
  2. Use atomic.AddInt64 for counters
  3. Copy loop variables or upgrade to Go 1.22

Detailed fix by platform

Go

  1. go test -race ./... and go run -race .

How to diagnose

  1. Report — Which two accesses?
  2. State — Shared how?
  3. Fix — Mutex/atomic/channel?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

all goroutines are asleep - deadlock — Go: fatal error: all goroutines are asleep - deadlock! (Go)all goroutines are as…fatal error: concurrent map read and map write — Go: fatal error: concurrent map read and map write (Go)fatal error: concurre…fatal error: concurrent map writes — Go: fatal error: concurrent map writes (Go)fatal error: concurre…listen tcp :8080: bind: address already in use — Go: listen tcp :8080: bind: address already in use (Go)listen tcp :8080: bin…panic: close of closed channel — Go: panic: close of closed channel (or close of nil channel) (Go)panic: close of close…panic: send on closed channel — Go: panic: send on closed channel (Go)panic: send on closed…panic: sync: negative WaitGroup counter — Go: panic: sync: negative WaitGroup counter (Go)panic: sync: negative…WARNING: …

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.