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 panic when merging a stalled stream log to an empty LogBuffer #3744

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 13 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@
# message = "Fix typos in module documentation for generated crates"
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"
# author = "rcoh"

[[aws-sdk-rust]]
message = "Fix bug where stalled stream protection would panic with an underflow if the first event was logged too soon."
references = ["smithy-rs#3744"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "Velfi"

[[smithy-rs]]
message = "Fix bug where stalled stream protection would panic with an underflow if the first event was logged too soon."
references = ["smithy-rs#3744"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"}
author = "Velfi"
18 changes: 9 additions & 9 deletions rust-runtime/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-runtime"
version = "1.6.1"
version = "1.6.2"
authors = ["AWS Rust SDK Team <[email protected]>", "Zelda Hessler <[email protected]>"]
description = "The new smithy runtime crate"
edition = "2021"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ struct LogBuffer<const N: usize> {
// polling gap. Once the length reaches N, it will never change again.
length: usize,
}

impl<const N: usize> LogBuffer<N> {
fn new() -> Self {
Self {
Expand Down Expand Up @@ -247,6 +248,11 @@ impl<const N: usize> LogBuffer<N> {
}
counts
}

/// If this LogBuffer is empty, returns `true`. Else, returns `false`.
fn is_empty(&self) -> bool {
return self.length == 0;
}
}

/// Report/summary of all the events in a time window.
Expand Down Expand Up @@ -334,7 +340,11 @@ impl ThroughputLogs {

fn push(&mut self, now: SystemTime, value: Bin) {
self.catch_up(now);
self.buffer.tail_mut().merge(value);
if self.buffer.is_empty() {
self.buffer.push(value)
} else {
self.buffer.tail_mut().merge(value);
}
self.buffer.fill_gaps();
}

Expand Down Expand Up @@ -552,4 +562,13 @@ mod test {
let report = logs.report(start + Duration::from_millis(999));
assert_eq!(ThroughputReport::Pending, report);
}

#[test]
fn test_first_push_succeeds_although_time_window_has_not_elapsed() {
let t0 = SystemTime::UNIX_EPOCH;
let t1 = t0 + Duration::from_secs(1);
let mut tl = ThroughputLogs::new(Duration::from_secs(1), t1);

tl.push_pending(t0);
}
}
Loading