Overview
Requests do not time out by default. Use context to configure a timeout for a request lifecycle.Setting Request Timeouts
You can configure two types of timeouts:- Overall timeout: The total time for the request including all retries
- Per-retry timeout: The time limit for each individual retry attempt
Complete Example
Timeout Types
Overall Timeout
Use Go’s standardcontext.WithTimeout() to set the total time allowed for the entire request, including all retry attempts.
The context timeout applies to the entire request lifecycle, including all retry attempts.
Per-Retry Timeout
Useoption.WithRequestTimeout() to set a timeout for each individual retry attempt.
The per-retry timeout resets for each retry attempt, allowing you to limit how long each individual attempt can take.
Best Practices
- Always use
defer cancel()when creating a context with timeout - Set reasonable per-retry timeouts to prevent individual attempts from hanging
- Consider the total number of retries when setting the overall timeout
- For long-running operations, use appropriate timeout values that account for expected processing time
