# http: read on closed response body

- **ID:** `go/http-response-body-not-closed`
- **Domain:** go
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Attempting to read from an http.Response.Body after it has already been closed, typically due to premature closing or multiple goroutines sharing the body.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Go 1.18 | active | — | — |
| Go 1.19 | active | — | — |
| Go 1.20 | active | — | — |
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |

## Workarounds

1. **Always defer resp.Body.Close() after checking for error, and read the body inside the defer scope** (95% success)
   ```
   Always defer resp.Body.Close() after checking for error, and read the body inside the defer scope
   ```
2. **Use a sync.Once or mutex if multiple goroutines need to read the same body** (85% success)
   ```
   Use a sync.Once or mutex if multiple goroutines need to read the same body
   ```

## Dead Ends

- **** — Closing the body before reading makes the data unavailable; the body must be read first, then closed. (80% fail)
- **** — If the body is already closed, ReadAll will panic; always check errors and ensure body is open. (70% fail)
