Skip to content

Update TokenBucket init to respect user TimeSource#4461

Merged
landonxjames merged 9 commits into
mainfrom
landonxjames/token-time-source
Jan 8, 2026
Merged

Update TokenBucket init to respect user TimeSource#4461
landonxjames merged 9 commits into
mainfrom
landonxjames/token-time-source

Conversation

@landonxjames
Copy link
Copy Markdown
Collaborator

@landonxjames landonxjames commented Dec 23, 2025

Still needs tests, but want to see if it breaks any existing CI first

Motivation and Context

Closes #4459, WASM users were seeing runtime errors because some new functionality added to the TokenBucket was creating a default TimeSource that used SystemTime. WASM is sandboxed and doesn't have access to SystemTime, so this caused a panic.

Description

I updated the TokenBucket to not carry a TimeSource. Instead the method that need the TimeSource take it as an input so the interceptors that use the TokenBucket can provide it from RuntimeComponents.

Testing

Added integration test to ensure that the TokenBucket for an operation picks up the TimeSource from the Config if it is set.

Note: I was going to beef up our WASM integration tests as part of this, but I ran into bytecodealliance/wit-bindgen#1479. So those updates are living in a separate branch for now, you can see the in-progress work here. Added a task to #2499 to update our WASM integration tests to make sure we catch issues like this in the future.

Note2: I still need to clean up that failing exotic platform test. I am using an AtomicU64 which is not available on that platform, but I need to confirm it will be safe to cast to u32.

Checklist

  • For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the .changelog directory, specifying "client," "server," or both in the applies_to key.
  • For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the .changelog directory, specifying "aws-sdk-rust" in the applies_to key.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link
Copy Markdown

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link
Copy Markdown

A new generated diff is ready to view.

A new doc preview is ready to view.

@landonxjames landonxjames marked this pull request as ready for review December 24, 2025 05:52
@landonxjames landonxjames requested review from a team as code owners December 24, 2025 05:52
Copy link
Copy Markdown
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance this seems a little weird.

I would have expected no changes other than having the TB read from RuntimeComponents.

Maybe this was the only way to do it?

@landonxjames
Copy link
Copy Markdown
Collaborator Author

landonxjames commented Dec 29, 2025

I would have expected no changes other than having the TB read from RuntimeComponents.

Discussed with Russell offline and this probably looks like:

  • Removing the stored TimeSource from the TokenBucket. This was only introduced recently in this PR which was yanked due to this bug, so should be safe to remove.
  • Then move the refill_tokens_based_on_time logic to the TokenBucketProvider interceptor so it can use the TimeSource from the RuntimeComponents directly without carrying it around.

I'm out most of the rest of this week, so will probably get to this next week. Moving this PR back to draft until that is done.

@landonxjames landonxjames marked this pull request as draft December 29, 2025 17:57
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 6, 2026

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 7, 2026

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@landonxjames landonxjames marked this pull request as ready for review January 7, 2026 17:05
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 8, 2026

A new generated diff is ready to view.

  • AWS SDK (ignoring whitespace)
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@landonxjames landonxjames merged commit aeb5e71 into main Jan 8, 2026
49 of 50 checks passed
@landonxjames landonxjames deleted the landonxjames/token-time-source branch January 8, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] TokenBucket ignores configured TimeSource and panics on WASM due to hardcoded SystemTime::now()

3 participants