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

only reset streams when retrying #1358

Merged
Merged
Show file tree
Hide file tree
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
11 changes: 3 additions & 8 deletions sdk/core/src/http_client/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@ impl HttpClient for ::reqwest::Client {

let reqwest_request = match body {
Body::Bytes(bytes) => req.body(bytes).build(),
Body::SeekableStream(mut seekable_stream) => {
seekable_stream.reset().await.context(
ErrorKind::Other,
"failed to reset body stream when building request",
)?;
req.body(::reqwest::Body::wrap_stream(seekable_stream))
.build()
}
Body::SeekableStream(seekable_stream) => req
.body(::reqwest::Body::wrap_stream(seekable_stream))
.build(),
}
.context(ErrorKind::Other, "failed to build `reqwest` request")?;

Expand Down
8 changes: 7 additions & 1 deletion sdk/core/src/policies/retry_policies/retry_policy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::error::{Error, ErrorKind, HttpError};
use crate::error::{Error, ErrorKind, HttpError, ResultExt};
use crate::policies::{Policy, PolicyResult, Request};
use crate::sleep::sleep;
use crate::{Context, StatusCode};
Expand Down Expand Up @@ -60,6 +60,12 @@ where
let mut start = None;

loop {
if retry_count > 0 {
request.body.reset().await.context(
ErrorKind::Other,
"failed to reset body stream before retrying request",
)?;
}
let result = next[0].send(ctx, request, &next[1..]).await;
// only start keeping track of time after the first request is made
let start = start.get_or_insert_with(OffsetDateTime::now_utc);
Expand Down
7 changes: 7 additions & 0 deletions sdk/core/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ impl Body {
pub fn is_empty(&self) -> bool {
self.len() == 0
}

pub(crate) async fn reset(&mut self) -> crate::Result<()> {
match self {
Body::Bytes(_) => Ok(()),
Body::SeekableStream(stream) => stream.reset().await,
}
}
}

impl<B> From<B> for Body
Expand Down