fatal error: concurrent map writes Go Origin: Application & API Last updated 4 Nov 2026

Go: fatal error: concurrent map writes

Two goroutines wrote to the same map at the same time; the runtime detects it and aborts the program (not recoverable).

Exact message you may see fatal error: concurrent map writesfatal error: concurrent map iteration and map writeconcurrent map writesfatal error: concurrent map writes goroutine
Seen on: Go

Meaning

Go maps are not safe for concurrent use. Protect with sync.Mutex/sync.RWMutex, use sync.Map for specific patterns, or confine the map to one goroutine and communicate via channels. Detect with go run -race.

Common causes

  • Handlers writing a shared map without a lock
  • Goroutines in a loop updating one map
  • Cache implemented as a plain map
  • Map shared via closure
  • Missing lock around read-modify-write

⚡ Quick fix

  1. Wrap access with a mutex
  2. Use sync.Map or a sharded design
  3. Run go test -race to find all racy accesses

Detailed fix by platform

Go

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

How to diagnose

  1. Access — Multiple goroutines?
  2. Lock — Protected?
  3. Race — Detector output?

🔧 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):

cannot assign to struct field m[k].f in map — Go: cannot assign to struct field users["bob"].Age in map (Go)cannot assign to stru…fatal error: concurrent map read and map write — Go: fatal error: concurrent map read and map write (Go)fatal error: concurre…panic: assignment to entry in nil map — Go: panic: assignment to entry in nil map (Go)panic: assignment to …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: DATA RACE — Go: WARNING: DATA RACE — Write at 0x00c0000 by goroutine 7: / Previous read at ... by goroutine 6 (Go)WARNING: DATA RACEfatal err…

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.