Retry transport-level failures during OAuth2 token refresh#2
Merged
Conversation
Extract the transport-retry logic (RemoteDisconnected, timeouts, reset connections) into a _request_with_transport_retry helper and use it for both _send and the OAuth2 token POST in _refresh_token. Previously only _send retried transport failures, so a transient network error during token refresh would abort the client. Bump to 1.0.4; add a test that the token POST is retried.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Only
_sendretried transport-level failures (RemoteDisconnected, timeouts, reset connections); the OAuth2 token POST in_refresh_tokendid not. So a transient network blip during token refresh would raise straight out and abort the caller's run — even though the same blip during a normal request is transparently retried.This extracts the transport-retry logic into a
_request_with_transport_retryhelper and uses it for both_sendand the token POST in_refresh_token. Behavior for_sendis unchanged (same 5-attempt backoff); the token refresh now gets the same resilience.Changes
_request_with_transport_retry(method, url, **kwargs)(5 attempts, 5s×attempt backoff, raisesHelpScoutErrorif all fail)._refresh_tokenand_sendboth route their request through it.Tests
Added
test_token_refresh_retries_transport_error(mirrors the existingresponses-based tests): a transport-level failure on the token POST is retried and the client still initializes.pytest— all 10 pass.Note: this is the fix currently carried in-tree in the devops-fabric consumer; upstreaming it so the published package matches.