# Go: fatal error: concurrent map writes

**Code:** `fatal error: concurrent map writes` · **Category:** Go · **Seen on:** Go

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/concurrent-map-writes)
