-
Notifications
You must be signed in to change notification settings - Fork 212
Description
Description
When retrying an HTTP request with a backoff duration, the code sleeps for the specified backoffDuration before attempting another retry. However, if the request's context (ctx) is cancelled during this sleep period, the sleep continues until the full duration completes, even though the operation is no longer needed.
This behavior causes unnecessary delays and violates the expected cancellation logic for long-running operations like retries.
Expected Behavior
If the context is cancelled while the system is sleeping between retries, the sleep should be interrupted immediately, and the operation should return an error indicating the cancellation. This will allow the system to avoid unnecessary waits and proceed with error handling or cancellation.
Steps to Reproduce
- Trigger an HTTP request retry with a backoff duration.
- Cancel the request's context before the sleep duration has elapsed.
- Observe that the sleep does not interrupt, and the operation continues past the cancellation.
Proposed Solution
- Modify the retry logic to check for context cancellation during the sleep period.
- Interrupt the sleep and immediately return an error when the context is cancelled.
Additional Notes
This issue leads to inefficient retries and can cause a lag in canceling operations that should have been aborted earlier.