Unverified Commit 2e50dab4 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Fix bug where paginators looped forever on empty string next token (#1054)

* Fix bug where paginators looped forever on empty string next token

* Update changelogs
parent a5554e06
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -15,3 +15,15 @@ message = "Fix typos for X-Ray trace ID environment variable in aws_http::recurs
references = ["smithy-rs#1050"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "nmoutschen"

[[aws-sdk-rust]]
message = "Fix critical paginator bug where an empty outputToken lead to a never ending stream."
references = ["smithy-rs#1054", "aws-sdk-rust#391"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"

[[smithy-rs]]
message = "Fix critical paginator bug where an empty outputToken lead to a never ending stream."
references = ["smithy-rs#1054", "aws-sdk-rust#391"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"
+1 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
[workspace]
members = [
    "dynamodb",
    "ec2",
    "iam",
    "kms",
    "polly",
+52 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ fn mk_response(body: &'static str) -> http::Response<SdkBody> {
    http::Response::builder().body(SdkBody::from(body)).unwrap()
}

#[tokio::test]
#[tokio::test(flavor = "current_thread")]
async fn paginators_loop_until_completion() {
    let conn = TestConnection::new(vec![
        (
@@ -169,3 +169,54 @@ async fn paginators_handle_errors() {
    rows.try_next().await.expect_err("failure");
    assert_eq!(rows.try_next().await.expect("ok"), None);
}

#[tokio::test]
async fn paginators_error_on_repeated_token() {
    let response = r#"{
        "Count": 1,
        "Items": [{
            "PostedBy": {
                "S": "joe@example.com"
            }
        }],
        "LastEvaluatedKey": {
            "PostedBy": { "S": "joe@example.com" }
        }
    }"#;
    // send the same response twice with the same pagination token
    let conn = TestConnection::new(vec![
        (
            mk_request(r#"{"TableName":"test-table","Limit":32}"#),
            mk_response(response),
        ),
        (
            mk_request(
                r#"{"TableName":"test-table","Limit":32,"ExclusiveStartKey":{"PostedBy":{"S":"joe@example.com"}}}"#,
            ),
            mk_response(response),
        ),
    ]);
    let client = Client::from_conf_conn(stub_config(), conn.clone());
    let mut rows = client
        .scan()
        .table_name("test-table")
        .into_paginator()
        .page_size(32)
        .items()
        .send();
    assert_eq!(
        rows.try_next()
            .await
            .expect("no error")
            .expect("not EOS")
            .get("PostedBy"),
        Some(&AttributeValue::S("joe@example.com".to_string()))
    );
    let err = rows.try_next().await.expect_err("failure");
    assert!(
        format!("{}", err).contains("next token did not change"),
        "{}",
        err
    );
    assert_eq!(rows.try_next().await.expect("ok"), None);
}
+11 −0
Original line number Diff line number Diff line
[package]
name = "ec2-tests"
version = "0.1.0"
edition = "2018"

[dev-dependencies]
aws-sdk-ec2 = { path = "../../build/aws-sdk/sdk/ec2" }
aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["test-util"]}
tokio = { version = "1", features = ["full"]}
http = "0.2.6"
tokio-stream = "0.1.8"
+4 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
Loading