fix: remove middleware retry limit (#87)

* refactor: Simplify retry middleware in reqwest.

Removed retry limit:

- Remove MAXIMUM_NUMBER_OF_RETRIES metadata and references in middleware.rs
- Correct mispelling: retry_decision to retry_decision in middleware.rs
- Update Retryable matching to only match Retryable::Transient in middleware.rs
- Simplify branching by removing n_past_retries < MAXIMUM_NUMBER_OF_RETRIES condition in middleware.rs

* test: Remove retry cap assertion from test file

remove retry limit assertion test
pull/88/head
Matthew Gapp 2023-04-17 05:02:13 -07:00 committed by GitHub
parent fef18b3506
commit f8ff599f50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 20 deletions

View File

@ -8,9 +8,6 @@ use reqwest_middleware::{Error, Middleware, Next, Result};
use retry_policies::RetryPolicy; use retry_policies::RetryPolicy;
use task_local_extensions::Extensions; use task_local_extensions::Extensions;
/// We limit the number of retries to a maximum of `10` to avoid stack-overflow issues due to the recursion.
static MAXIMUM_NUMBER_OF_RETRIES: u32 = 10;
/// `RetryTransientMiddleware` offers retry logic for requests that fail in a transient manner /// `RetryTransientMiddleware` offers retry logic for requests that fail in a transient manner
/// and can be safely executed again. /// and can be safely executed again.
/// ///
@ -102,14 +99,11 @@ impl<T: RetryPolicy + Send + Sync> RetryTransientMiddleware<T> {
// We classify the response which will return None if not // We classify the response which will return None if not
// errors were returned. // errors were returned.
break match Retryable::from_reqwest_response(&result) { break match Retryable::from_reqwest_response(&result) {
Some(retryable) Some(Retryable::Transient) => {
if retryable == Retryable::Transient
&& n_past_retries < MAXIMUM_NUMBER_OF_RETRIES =>
{
// If the response failed and the error type was transient // If the response failed and the error type was transient
// we can safely try to retry the request. // we can safely try to retry the request.
let retry_decicion = self.retry_policy.should_retry(n_past_retries); let retry_decision = self.retry_policy.should_retry(n_past_retries);
if let retry_policies::RetryDecision::Retry { execute_after } = retry_decicion { if let retry_policies::RetryDecision::Retry { execute_after } = retry_decision {
let duration = (execute_after - Utc::now()) let duration = (execute_after - Utc::now())
.to_std() .to_std()
.map_err(Error::middleware)?; .map_err(Error::middleware)?;

View File

@ -151,17 +151,6 @@ assert_retry_succeeds!(429, StatusCode::OK);
assert_no_retry!(431, StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE); assert_no_retry!(431, StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE);
assert_no_retry!(451, StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS); assert_no_retry!(451, StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS);
// We assert that we cap retries at 10, which means that we will
// get 11 calls to the RetryResponder.
assert_retry_succeeds_inner!(
500,
assert_maximum_retries_is_not_exceeded,
StatusCode::INTERNAL_SERVER_ERROR,
100,
11,
RetryResponder::new(100_u32, 500)
);
pub struct RetryTimeoutResponder(Arc<AtomicU32>, u32, std::time::Duration); pub struct RetryTimeoutResponder(Arc<AtomicU32>, u32, std::time::Duration);
impl RetryTimeoutResponder { impl RetryTimeoutResponder {