# WARNING: DATA RACE: Write by goroutine X, Read by goroutine Y (http.Handler)

- **ID:** `go/goroutine-http-server-race`
- **Domain:** go
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Multiple HTTP handler goroutines accessing shared state without synchronization.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.0 | active | — | — |
| 1.21 | active | — | — |

## Workarounds

1. **Use local variables within handler** (95% success)
   ```
   http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    var counter int
    counter++
    fmt.Fprintf(w, "%d", counter)
})
   ```
2. **Use sync.Mutex for shared state** (90% success)
   ```
   var mu sync.Mutex
var counter int
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    mu.Lock()
    counter++
    mu.Unlock()
    fmt.Fprintf(w, "%d", counter)
})
   ```

## Dead Ends

- **Using global variables for request state** — Global variables are shared across all requests; race condition. (90% fail)
- **Using request-scoped variables incorrectly** — If variable is captured by closure, it may be shared. (70% fail)
