Skip to content

Bugfix/async user agent nonblocking identity - #7562

Open
steinybot wants to merge 4 commits into
aws:masterfrom
steinybot:bugfix/async-user-agent-nonblocking-identity
Open

steinybot wants to merge 4 commits into
aws:masterfrom
steinybot:bugfix/async-user-agent-nonblocking-identity

Conversation

@steinybot

Copy link
Copy Markdown

ApplyUserAgentStage now checks the client type and will omit the provider name if the client type is async and the identity has yet to be resolved. Once it has been resolved (assuming it is cached) then it includes it in future requests. Every built-in AwsCredentialsProvider or SdkTokenProvider blocks the calling thread (they really shouldn't but that is a separate issue) and so it will be resolved and this change has no effect.

The alternative solution would be to move this stage to a different part of the pipeline so that it could run after identity resolution is guaranteed to have finished but that is a larger change.

Motivation and Context

Fixes #7560

Modifications

  • Add a ClientType parameter to the ApplyUserAgentStage constructor.
  • Pass it as either ASYNC or SYNC depending on whether it is called from AmazonAsyncHttpClient or AmazonSyncHttpClient.
  • Within ApplyUserAgentStage, change getBusinessMetricsString and credentialProviderBusinessMetrics to be instance methods so that they can access the clientType field.
  • Add a method resolvedIdentity which checks the clientType and whether the identity future has completed:
    • If it is ASYNC and it has not completed then it returns no Identity.
    • If it is ASYNC and it has completed normally then it returns the resolved Identity.
    • If it is ASYNC and it has completed exceptionally then it throws.
    • Otherwise it is SYNC and it blocks as it did previously.

Testing

Ran:
./mvnw install -pl :sdk-core
./mvnw clean install

ServerNotRespondingTest is flakey. ServerConnectivityErrorMessageTest fails every time and seems to be environmental.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance improvement (non-breaking change which improves latency, throughput, or resource use)
  • Deprecation (marks existing functionality as deprecated)
  • Removal (removes previously deprecated functionality)
  • Documentation (changes to documentation only)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

AI tools

  • I wrote this pull request description myself, not with an AI tool
  • I have reviewed all changes in this pull request myself, including any generated by AI tools

License

  • I confirm that this pull request can be released under the Apache 2 license

steinybot and others added 3 commits November 17, 2026 12:38
ApplyUserAgentStage runs on the calling thread in the async pipeline and
joined the selected auth scheme's identity future to read the credential
provider name for the User-Agent business metric. Async clients therefore
blocked their caller until credentials resolved, even though signing
already waits on the identity future asynchronously.

The stage now takes the client type. For async clients it reads the
provider name only when the identity future has already completed
normally, and otherwise leaves the credential provider metric out of the
User-Agent. Sync clients still wait for the identity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replaces the hand-rolled executor and Future.get timeout with JUnit's
assertTimeoutPreemptively, which runs the call on its own thread and
fails the test if it does not return in time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The async path only needs to avoid waiting on an identity that is still
being resolved. An identity future that has already completed
exceptionally can be joined without blocking, so join it as before and
let the failure surface from this stage, rather than skipping the metric
and deferring the failure to signing inside the retry loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@steinybot
steinybot requested a review from a team as a code owner November 17, 2026 01:36
Copilot AI balanced review requested due to automatic review settings November 17, 2026 01:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The regression test needs a timeout because its identity future never completes, so reintroducing the blocking join would hang the test indefinitely rather than fail it.

1 open issue
What changed in this PR

This PR addresses the User-Agent blocking issue in #7560 within the SDK’s core HTTP pipeline. Async clients omit the credential provider metric while identity resolution is pending, while sync clients retain their existing waiting behavior.

Changes:

  • Pass the client type into ApplyUserAgentStage and avoid waiting for unresolved async identities.
  • Add stage-level tests and an async pipeline regression test.
  • Add a release note describing the fix.
File Description
core/​sdk-core/​src/​test/​java/​software/​amazon/​awssdk/​core/​internal/​http/​pipeline/​stages/​ApplyUserAgentStageTest.java Tests resolved, pending, and failed identities and sync waiting behavior.
core/​sdk-core/​src/​test/​java/​software/​amazon/​awssdk/​core/​internal/​http/​AsyncHttpClientIdentityResolutionTest.java Checks that async execution returns while identity resolution is pending.
core/​sdk-core/​src/​main/​java/​software/​amazon/​awssdk/​core/​internal/​http/​pipeline/​stages/​ApplyUserAgentStage.java Skips pending identity metrics for async clients.
core/​sdk-core/​src/​main/​java/​software/​amazon/​awssdk/​core/​internal/​http/​AmazonSyncHttpClient.java Supplies the sync client type to the stage.
core/​sdk-core/​src/​main/​java/​software/​amazon/​awssdk/​core/​internal/​http/​AmazonAsyncHttpClient.java Supplies the async client type to the stage.
.changes/​next-release/​bugfix-AWSSDKforJavav2-7084844.json Documents the nonblocking User-Agent change.

Review effort: Balanced

The identity future in this test never completes, so a regression back
to a blocking join would hang the build instead of failing the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change to avoid blocking async requests while collecting credential-provider metrics.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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.

Async clients block the calling thread until credentials resolve (ApplyUserAgentStage joins the identity future)

2 participants