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

Retry bug #238

Merged
merged 2 commits into from
Mar 5, 2021
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
17 changes: 15 additions & 2 deletions aws/rust-runtime/aws-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::time::Duration;
#[derive(Clone)]
pub struct AwsErrorRetryPolicy;

const TRANSIENT_ERROR_STATUS_CODES: [u16; 2] = [400, 408];
const TRANSIENT_ERROR_STATUS_CODES: &[u16] = &[500, 502, 503, 504];
const THROTTLING_ERRORS: &[&str] = &[
"Throttling",
"ThrottlingException",
Expand Down Expand Up @@ -137,7 +137,7 @@ mod test {
fn classify_by_response_status() {
let policy = AwsErrorRetryPolicy::new();
let test_resp = http::Response::builder()
.status(408)
.status(500)
.body("error!")
.unwrap();
assert_eq!(
Expand All @@ -146,6 +146,19 @@ mod test {
);
}

#[test]
fn classify_by_response_status_not_retryable() {
let policy = AwsErrorRetryPolicy::new();
let test_resp = http::Response::builder()
.status(408)
.body("error!")
.unwrap();
assert_eq!(
policy.classify(make_err(UnmodeledError, test_resp).as_ref()),
RetryKind::NotRetryable
);
}

#[test]
fn classify_by_error_code() {
let test_response = http::Response::new("OK");
Expand Down
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-hyper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ smithy-types = { path = "../../../rust-runtime/smithy-types" }
smithy-http-tower = { path = "../../../rust-runtime/smithy-http-tower" }
fastrand = "1.4.0"
tokio = { version = "1", features = ["time"]}
tracing = "0.1.25"

[dev-dependencies]
tokio = { version = "1", features = ["full", "test-util"] }
Expand Down
9 changes: 5 additions & 4 deletions aws/rust-runtime/aws-hyper/src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::future::Future;
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use tracing::Instrument;

/// Retry Policy Configuration
///
Expand Down Expand Up @@ -249,17 +250,17 @@ where
) -> Option<Self::Future> {
let policy = req.retry_policy();
let retry = policy.classify(result);
let (next, fut) = match retry {
let (next, dur) = match retry {
RetryKind::Explicit(dur) => (self.clone(), dur),
RetryKind::NotRetryable => return None,
RetryKind::Error(err) => self.attempt_retry(Err(err))?,
_ => return None,
};
let fut = async move {
tokio::time::sleep(fut).await;
tokio::time::sleep(dur).await;
next
};
Some(Box::pin(fut))
}.instrument(tracing::info_span!("retry", kind = &debug(retry)));
Some(Box::pin(fut))
}

fn clone_request(&self, req: &Operation<Handler, R>) -> Option<Operation<Handler, R>> {
Expand Down