# error: net/http: request canceled (Client.Timeout or context cancellation)

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

## Root Cause

The client canceled the HTTP request due to timeout or explicit context cancellation before the server responded.

## Version Compatibility

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

## Workarounds

1. **Use a custom context with proper timeout and cancellation handling** (90% success)
   ```
   ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
req, _ := http.NewRequestWithContext(ctx, "GET", url, nil)
resp, err := client.Do(req)
if errors.Is(err, context.Canceled) { /* handle gracefully */ }
   ```

## Dead Ends

- **Increasing client timeout indefinitely without handling context** — Context cancellation can still occur from upstream, leading to same error; indefinite timeout is not scalable. (70% fail)
- **Ignoring the error and retrying blindly** — Retrying without checking context may amplify load and cause cascading failures. (80% fail)
