# http: write on closed connection

- **ID:** `go/http-write-after-shutdown`
- **Domain:** go
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to write a response to a client connection that has already been closed, often due to a timeout or client disconnect.

## Version Compatibility

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

## Workarounds

1. **** (85% success)
   ```
   if err := json.NewEncoder(w).Encode(data); err != nil {
    log.Printf("Error writing response: %v", err)
}
   ```
2. **** (80% success)
   ```
   Use context cancellation to detect client disconnects early.
   ```

## Dead Ends

- **** — The write will fail silently, and the client will never receive the response. (70% fail)
- **** — The issue is not buffer size but connection state. (90% fail)
