Skip to content

Conversation

@mohitsethia
Copy link

@mohitsethia mohitsethia commented Mar 30, 2025

Summary

Currently, when an HTTP request is retried, it sleeps for backoffDuration before making another attempt. However, if the request's context (ctx) gets cancelled during this sleep period, the function does not exit immediately and instead continues to sleep until the duration completes.

This PR fixes the issue by checking for context cancellation during the sleep and interrupting it early, returning an appropriate error instead of waiting unnecessarily.

Changes Introduced

  • Added a check to interrupt sleep if the context is cancelled.
  • Ensured the function exits immediately when cancellation is detected, improving responsiveness.
  • Added/updated test cases to verify correct behavior.

Impact

  • Prevents unnecessary delays when retries are no longer needed.
  • Improves efficiency in request handling.
  • Aligns behavior with expected cancellation semantics.

Testing

  • Verified the fix with unit tests covering both normal and cancelled scenarios.
  • Ensured no regressions in retry logic.

@mohitsethia mohitsethia force-pushed the fix-interrupt-retry-sleep-on-ctx-cancel branch from e52adbc to 55096d1 Compare March 30, 2025 18:10
@mohitsethia
Copy link
Author

Hi @rShetty @sohamkamani @devdinu @gwthm-in , not sure whom I can tag, can you guys please help review this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant