Repository navigation
Description
Describe the bug
IdentityProvider.resolveIdentity returns a CompletableFuture, and the async pipeline signs with identityFuture.thenCompose(...) in AsyncSigningStage. So an identity provider that loads credentials off-thread should let an async client's caller carry on while the credentials load.
It doesn't. ApplyUserAgentStage runs on the calling thread, inside AmazonAsyncHttpClient.RequestExecutionBuilderImpl.execute, and credentialProviderBusinessMetrics calls CompletableFutureUtils.joinLikeSync(selectedAuthScheme.identity()) to read Identity.providerName() for the User-Agent business metric. Every async call therefore blocks its caller until the identity resolves. With a cold provider (IMDS, container credentials, STS, SSO) that is the full time to load credentials, up to the provider's timeout.
The stage skips this only when the client or the request sets its own User-Agent header.
Regression Issue
- Select this option if this issue appears to be a regression.
The join came in with #6457 ("Add Business Metrics for Credential Providers"), first released in 2.35.0.
Expected Behavior
SqsAsyncClient.sendMessage(...) (or any async client operation) returns a CompletableFuture straight away, and the request goes out once the identity future completes.
Current Behavior
The call doesn't return until the identity future completes. With a provider whose future never completes, it hangs on the calling thread (stack abbreviated):
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java)
at software.amazon.awssdk.utils.CompletableFutureUtils.joinLikeSync(CompletableFutureUtils.java)
at software.amazon.awssdk.core.internal.http.pipeline.stages.ApplyUserAgentStage.credentialProviderBusinessMetrics(ApplyUserAgentStage.java)
at software.amazon.awssdk.core.internal.http.pipeline.stages.ApplyUserAgentStage.getBusinessMetricsString(ApplyUserAgentStage.java)
at software.amazon.awssdk.core.internal.http.pipeline.stages.ApplyUserAgentStage.finalizeUserAgent(ApplyUserAgentStage.java)
at software.amazon.awssdk.core.internal.http.pipeline.stages.ApplyUserAgentStage.execute(ApplyUserAgentStage.java)
...
at software.amazon.awssdk.core.internal.http.AmazonAsyncHttpClient$RequestExecutionBuilderImpl.execute(AmazonAsyncHttpClient.java)
...
at software.amazon.awssdk.services.sqs.DefaultSqsAsyncClient.sendMessage(DefaultSqsAsyncClient.java)
Reproduction Steps
CompletableFuture<AwsCredentialsIdentity> pending = new CompletableFuture<>();
AwsCredentialsProvider slowProvider = new AwsCredentialsProvider() {
@Override
public AwsCredentials resolveCredentials() {
throw new UnsupportedOperationException();
}
@Override
public CompletableFuture<AwsCredentialsIdentity> resolveIdentity(ResolveIdentityRequest request) {
return pending; // credentials still loading on another thread
}
};
try (SqsAsyncClient sqs = SqsAsyncClient.builder()
.region(Region.US_EAST_1)
.credentialsProvider(slowProvider)
.build()) {
long start = System.nanoTime();
CompletableFuture<SendMessageResponse> response =
sqs.sendMessage(r -> r.queueUrl("https://sqs.us-east-1.amazonaws.com/123456789012/q").messageBody("hi"));
// Never reached: sendMessage blocks in ApplyUserAgentStage until `pending` completes.
System.out.println("returned after " + Duration.ofNanos(System.nanoTime() - start));
}Possible Solution
In ApplyUserAgentStage, an async client should read the provider name only when the identity future has already completed, and otherwise leave the credential provider metric out of the User-Agent. The sync pipeline joins the identity during signing anyway, so it can keep waiting. I have a PR with this change and tests.
Additional Information/Context
Generated endpoint code has the same pattern for services with account-ID based endpoints (for example DynamoDB). EndpointParamsKnowledgeIndex.accountIdFromIdentityMethod generates an accountIdFromIdentity that calls CompletableFutureUtils.joinLikeSync(selectedAuthScheme.identity()) while resolving endpoint parameters, so DynamoDbAsyncClient calls also block their caller until credentials load. That one needs the account ID before the endpoint is known, so it doesn't have the same easy fix and isn't part of my PR.
AWS Java SDK version used
2.59.2 (also seen on 2.57.0)
JDK version used
openjdk 21.0.13
Operating System and version
macOS (Darwin 27.0.0)
AI tools
- I have reviewed this issue myself, including any content generated by AI tools
🤖 Co-authored by Claude
Activity
adev-code commentedon Nov 17, 2026
Hi @steinybot, thanks for reaching out. I repro'd this with your code against SQS (us-east-1, Java 21), using a provider that loads real credentials on another thread and takes 3 seconds. On every version I tried,
listQueues()only returned after about 3 seconds, once the credentials were loaded: 2.21.0, 2.35.0, 2.46.21, 2.47.0, 2.57.0 and 2.59.2. The thread is waiting inApplyUserAgentStage, as you described.I also see the same wait before 2.35.0: #6457 replaced an earlier join in the same stage, added in #5047. Have you seen an earlier version where the call returned right away, and then it started waiting after you upgraded? If so, which version did it work on, and which version did it stop on?
In the meantime, setting your own
User-Agentheader on the client skips this step. In my test that made the call return in about 40 ms on 2.47.0 and later.