# fatal error: concurrent map iteration and map write

- **ID:** `go/concurrent-map-write-during-range`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A map is being range-iterated in one goroutine while another goroutine writes to the same map, violating Go's map safety rules.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.18 | active | — | — |
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## Workarounds

1. **** (97% success)
   ```
   var mu sync.RWMutex
mu.RLock()
for k, v := range m { _ = k; _ = v }
mu.RUnlock()
// writer:
mu.Lock()
m[k] = v
mu.Unlock()
   ```
2. **** (90% success)
   ```
   var m sync.Map
m.Range(func(k, v any) bool { return true })
m.Store(key, val)
   ```

## Dead Ends

- **** — Timing-based avoidance is unreliable; the runtime can still detect concurrent access under load. (90% fail)
- **** — This is a fatal runtime error, not a panic; recover cannot catch it and the process exits. (95% fail)
