Skip to content
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

fix erroneous retries on a failed request to a newly opened socket #150

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions src/client/legacy/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ macro_rules! e {
type PoolKey = (http::uri::Scheme, http::uri::Authority);

enum TrySendError<B> {
Retryable { error: Error, req: Request<B> },
Retryable {
error: Error,
req: Request<B>,
connection_reused: bool,
},
Nope(Error),
}

Expand Down Expand Up @@ -244,8 +248,12 @@ where
req = match self.try_send_request(req, pool_key.clone()).await {
Ok(resp) => return Ok(resp),
Err(TrySendError::Nope(err)) => return Err(err),
Err(TrySendError::Retryable { mut req, error }) => {
if !self.config.retry_canceled_requests {
Err(TrySendError::Retryable {
mut req,
error,
connection_reused,
}) => {
if !self.config.retry_canceled_requests || !connection_reused {
// if client disabled, don't retry
// a fresh connection means we definitely can't retry
return Err(error);
Expand Down Expand Up @@ -317,6 +325,7 @@ where
Err(mut err) => {
return if let Some(req) = err.take_message() {
Err(TrySendError::Retryable {
connection_reused: pooled.is_reused(),
error: e!(Canceled, err.into_error())
.with_connect_info(pooled.conn_info.clone()),
req,
Expand All @@ -329,8 +338,6 @@ where
}
}
};
//.send_request_retryable(req)
//.map_err(ClientError::map_with_reused(pooled.is_reused()));

// If the Connector included 'extra' info, add to Response...
if let Some(extra) = &pooled.conn_info.extra {
Expand Down Expand Up @@ -803,26 +810,6 @@ impl<B: Body + 'static> PoolClient<B> {
PoolTx::Http2(ref mut tx) => tx.try_send_request(req),
};
}

/*
//TODO: can we re-introduce this somehow? Or must people use tower::retry?
fn send_request_retryable(
&mut self,
req: Request<B>,
) -> impl Future<Output = Result<Response<hyper::body::Incoming>, (Error, Option<Request<B>>)>>
where
B: Send,
{
match self.tx {
#[cfg(not(feature = "http2"))]
PoolTx::Http1(ref mut tx) => tx.send_request_retryable(req),
#[cfg(feature = "http1")]
PoolTx::Http1(ref mut tx) => Either::Left(tx.send_request_retryable(req)),
#[cfg(feature = "http2")]
PoolTx::Http2(ref mut tx) => Either::Right(tx.send_request_retryable(req)),
}
}
*/
}

impl<B> pool::Poolable for PoolClient<B>
Expand Down