Skip to content

Context cancellation not interrupting retry sleep in HTTP request #145

@mohitsethia

Description

@mohitsethia

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions