-
Notifications
You must be signed in to change notification settings - Fork 229
Refactor pub http retry behavior #3325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
type-enhancement
A request for a change that isn't a bug
Comments
I've captured the current state of the current retry logic so we can reference it while refactoring. Caveat: the sequenceDiagram
_download ->> retry(): <invoke>
retry() ->> _AuthenticatedClient: make new request and .send()
_AuthenticatedClient ->> _ThrottleClient: insert auth headers and .send()
Note over _AuthenticatedClient, _ThrottleClient: ⏳ _ThrottleClient can (re)throw PubHttpException<br/>_AuthenticatedClient catches and if status code is 403,<br/>throws AuthenticationException 🚨
_ThrottleClient ->> _ThrowingClient: gently .send()
_ThrowingClient ->> RetryClient: .send()
Note over _ThrowingClient,RetryClient: ⏳ RetryClient can (re)throw SocketException<br/>_ThrowingClient catches and calls fail() 🛑 on specific error codes.<br/>Otherwise, it rethrows 🚨
RetryClient ->> _PubHttpClient: .send() cloned, finalized request
Note over RetryClient,_PubHttpClient: ⏳ _PubHttpClient can (re)throw IOException<br/><br/>RetryClient catches and calls .send() again if attempts left
_PubHttpClient ->> http.BaseClient: insert Pub headers and .send()
http.BaseClient ->> _PubHttpClient: Sucessful response or<br/>bad response
_PubHttpClient ->> RetryClient: Sucessful response or<br/>bad response
RetryClient ->> RetryClient: Checks for status codes 500, 502, 503, and 504<br/>and calls .send() again if attempts left
RetryClient ->> _ThrowingClient: Sucessful response or<br/>bad response after retry limit
_ThrowingClient ->> _ThrowingClient: Checks for status code `< 400`, `== 401`, or `== 400 && isTokenRequest`. If match, returns response ⬅️<br/>Else, checks for status code 406 and 'Accept' request header. If match, calls fail() 🛑<br/>Else, checks for status code 500 and request url host. If match, calls fail() 🛑<br/>Finally, throws PubHttpException before fall through 🚨
_ThrowingClient ->> _ThrottleClient: Successful response or<br/>bad auth response
_ThrottleClient ->> _AuthenticatedClient: Successful response or<br/>bad auth response
_AuthenticatedClient ->> _AuthenticatedClient: If status code is 401,<br/>throws AuthenticationException 🚨
_AuthenticatedClient ->> retry(): Successful response
retry() ->> retry(): Validates CRC32C if applicable<br/>Catches PackageIntegrityException and retry()s if attempts left
retry() ->> _download: Validated response
|
jonasfj
added a commit
that referenced
this issue
Nov 9, 2022
* Break out networking related OS error codes * Add mapException feature to retry util * Add WIP sendWithRetries method * Fix potential runtime null response in onRetry option * Remove code to get CI working * Apply suggestions from code review Co-authored-by: Jonas Finnemann Jensen <[email protected]> * Update Pub HTTP exceptions * Remove stack trace from retry methods * Remove hard-coded domain check for HTTP 500 * Simplify method * Align retry behavior with requirements * Move withAuthenticatedClient a layer up and clarify comment * Clarify usage of global HTTP client * Take request metadata out of _PubHttpClient * Use RetryClient for OAuth2 calls * Retrigger checks * Wrap versions HTTP call with retryForHttp * Add more comments * Use "throwIfNotOk" in versions HTTP call * Change PackageIntegrityException to always subclass as an intermittent PubHttpException * Configure OAuth2 HTTP retries * Make metadata headers method an extension on http.Request and use .throwIfNotOk() in more places * Add retries to OIDC discovery document request * Add some retries to upload command * Add retries to upload package step * Fix indentation * Make PubHttpResponseException use BaseResponse * Fix get_test * Fix more tests * Fix SHA-256 tests * Only send pub.dev API Accept header when necessary and fix tests Co-authored-by: Jonas Finnemann Jensen <[email protected]>
#3590 improves retries and addresses some of these issues:
|
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
timeouts on dns lookups (if possible)
timeouts on http requests
=> timeout 30 seconds on request-> response headers
timeouts on body download
Length limits:
x-goog-hash
header is present #2281Improved error behavior:
The text was updated successfully, but these errors were encountered: