Skip to content

SsoProfileCredentialsProvider.close() leaks the SsoOidcClient of an sso_session profile #7545

Open

Description

@pjgjordaan

Describe the bug

SsoProfileCredentialsProvider for a profile that uses sso_session builds an SsoOidcClient to refresh the SSO token. Closing the provider doesn't close that client. Its connection pool stays registered with IdleConnectionReaper. The idle-connection-reaper thread keeps running after the client and provider has been closed.

SsoProfileCredentialsProvider.close() closes its SsoClient but not its token provider, which owns the SsoOidcClient. The token provider is never stored in a field, which means that close() can never reach it.

A profile in the legacy format, without sso_session, gets an SsoAccessTokenProvider that only reads the cached token file. That path doesn't leak.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

After ProfileCredentialsProvider.close(), every SDK client that the provider built is closed, and no idle-connection-reaper thread is left when the application closed all its own clients.

Current Behavior

The idle-connection-reaper daemon thread keeps running. For our CLI running mvn exec:java, which joins leftover threads before it exits, every run waits about 15 seconds after its work is done.

Reproduction Steps

~/.aws/config, signed in with aws sso login --profile my-sso:

[profile my-sso]
sso_session = my-session
sso_account_id = 111122223333
sso_role_name = ReadOnly
region = eu-west-1

[sso-session my-session]
sso_start_url = https://example.awsapps.com/start
sso_region = eu-west-1
sso_registration_scopes = sso:account:access

With software.amazon.awssdk:sso, ssooidc and apache-client on the classpath:

import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;

public class SsoSessionLeak {
  public static void main(String[] args) throws Exception {
    try (ProfileCredentialsProvider provider = ProfileCredentialsProvider.create("my-sso")) {
      provider.resolveCredentials();
    }
    Thread.sleep(2000);
    Thread.getAllStackTraces().keySet().stream()
        .filter(t -> t.getName().equals("idle-connection-reaper"))
        .forEach(t -> System.out.println("still running: " + t.getName()));
    System.out.println("done");
  }
}

Output:

still running: idle-connection-reaper
done

Possible Solution

Keep the SdkTokenProvider in a field of SsoProfileCredentialsProvider and close it in close(), as it does for ssoClient:

@Override
public void close() {
    IoUtils.closeQuietly(credentialsProvider, null);
    IoUtils.closeQuietly(ssoClient, null);
    IoUtils.closeIfCloseable(tokenProvider, null);
}

As a workaround, we pick the URLConnection HTTP client for the whole SDK because it has no reaper thread:

System.setProperty("software.amazon.awssdk.http.service.impl",
    "software.amazon.awssdk.http.urlconnection.UrlConnectionSdkHttpService");

Additional Information/Context

No response

AWS Java SDK version used

2.57.7

JDK version used

OpenJDK 21.0.13

Operating System and version

macOS 26.5.1

AI tools

  • I have reviewed this issue myself, including any content generated by AI tools

Activity

  1. added
    bug
    needs-triage
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions