# Get "https://api.example.com/data": context deadline exceeded

- **ID:** `go/http-request-canceled-context`
- **Domain:** go
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The http.Client request context timed out or was canceled before the server responded. Often caused by a too-short context.WithTimeout, a slow upstream, or reusing a canceled context across requests.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
resp, err := client.Do(req)
   ```
2. **** (80% success)
   ```
   Use context.WithoutCancel(parentCtx) when a downstream call must outlive the parent request lifetime.
   ```

## Dead Ends

- **** — If the deadline comes from the request context, the client Timeout is irrelevant; the context still fires first. (70% fail)
- **** — Retrying with the same canceled context immediately fails again and amplifies load. (85% fail)
