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

Mysterious "Connection Pool Closed" Error #4221

Closed
Khongchai opened this issue Jun 30, 2023 · 6 comments
Closed

Mysterious "Connection Pool Closed" Error #4221

Khongchai opened this issue Jun 30, 2023 · 6 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.

Comments

@Khongchai
Copy link

Khongchai commented Jun 30, 2023

Describe the bug

Calling putObject with the s3AsyncClient from software.amazon.awssdk.services.s3.S3AsyncClient while using WebIdentityTokenFileCredentialsProvider as the credential provider will cause the "connection pool closed" error from AwsSyncClientHandler the STS library uses.

We were using AWS SDK version 2.20.19. Upgrading to newer ones didn't solve our problem, but when we downgraded to 2.16.18 the problem disappeared.

When this error happens, all subsequent requests to the endpoint that uses this library will throw the same error, the only solution is to restart the microservice. I will provide the stack trace here, this stack shows the assertion error at the HTTP client level, but we don't know who closed it (still trying to reproduce it locally so we can use the debugger to help us).

image

Expected Behavior

The error should not be thrown. We didn't call any close on any HTTP client or thread pools.

Current Behavior

Once we deploy our microservice, it will function normally, then fail within an hour -- likely after having handled a number of requests from our test team.

Reproduction Steps

Initialization

final var httpClient = SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder()
                .connectionTimeout(Duration.ofMillis(60000)
                .writeTimeout(Duration.ofMillis(60000)
                .readTimeout(Duration.ofMillis(60000)
                .maxConcurrency(8)
                .maxPendingConnectionAcquires(10000)
                .build();
final var credentialsProvider =  WebIdentityTokenFileCredentialsProvider.builder()
                    .roleArn(assumeRoleARN)
                    .webIdentityTokenFile(Path.of(tokenPath))
                    .build();
S3AsyncClientBuilder s3AsyncClientBuilder = S3AsyncClient.builder()
                .httpClient(httpClient)
                .region("ap-southeast-1")
                .credentialsProvider(credentialsProvider)
                .serviceConfiguration(serviceConfiguration)  // S3Configuration instance
                .build();

this. asyncClient = s3AsyncClientBuilder.build(); 

Calling putObject

asyncClient 
                .putObject(
                        PutObjectRequest.builder()
                                .bucket(...)
                                .contentLength(...)
                                .contentType(...)
                                .metadata(...)
                                .key(...)
                                .build(),
                        fileByte
                );

Calling putObject with this setup code a few times...or sporadically for an hour and the error appeared.

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

2.20.19

JDK version used

jdk-11

Operating System and version

"linux", version: "3.10.0-1160.6.1.el7.x86_64", arch: "amd64", family: "unix"

@Khongchai Khongchai added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 30, 2023
@debora-ito
Copy link
Member

"Connection Pool Closed" indicates the connection pool was closed prematurely.

The SDK does not close pools that are active. If you didn't explicitly closed the client, look for processes external to the SDK that can be closing the STS client, sometimes indirectly. Also, investigate the logs for any OutOfMemory errors. Sometimes the underlying HTTP client closes the connection pool if there's an error.

Can you provide the stacktrace that shows the "Connection Pool Closed" message?
It does not show in the printscreen of the stacktrace.

Moving this to the aws-sdk-java-v2 repo.

@debora-ito debora-ito removed the needs-triage This issue or PR still needs to be triaged. label Jul 20, 2023
@debora-ito debora-ito transferred this issue from aws/aws-sdk-java Jul 20, 2023
@debora-ito debora-ito self-assigned this Jul 20, 2023
@debora-ito debora-ito added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. p2 This is a standard priority issue labels Jul 20, 2023
@github-actions
Copy link

It looks like this issue has not been active for more than five days. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please add a comment to prevent automatic closure, or if the issue is already closed please feel free to reopen it.

@github-actions github-actions bot added the closing-soon This issue will close in 4 days unless further comments are made. label Jul 26, 2023
@pewtpong
Copy link

Hello, I am here to continue Khongchai's work. Our behavior is similar to the issue described in this link: [BUG: S3 Connection pool shut down for S3Client](aws/aws-sdk-java#1282) Currently, I am in the process of reproducing the problem, and I will promptly post the results of the reproduction once it is completed.

@github-actions github-actions bot removed closing-soon This issue will close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. labels Jul 26, 2023
@debora-ito
Copy link
Member

@pewtpong noted.

@debora-ito debora-ito added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Jul 26, 2023
@github-actions
Copy link

It looks like this issue has not been active for more than five days. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please add a comment to prevent automatic closure, or if the issue is already closed please feel free to reopen it.

@github-actions github-actions bot added closing-soon This issue will close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will close in 4 days unless further comments are made. labels Jul 31, 2023
@github-actions github-actions bot closed this as completed Aug 3, 2023
@chenlin2001
Copy link

I can see the same issue. I'm using Micronaut aws sdk which creates the credentials this way:
` */
@factory
@BootstrapContextCompatible
public class CredentialsAndRegionFactory {

/**
 * @param environment The {@link Environment}
 * @return An {@link AwsCredentialsProviderChain} that attempts to read the values from the Micronaut environment
 * first, then delegates to {@link DefaultCredentialsProvider}.
 */
@Bean(preDestroy = "close")
@Singleton
public AwsCredentialsProviderChain awsCredentialsProvider(Environment environment) {
    return AwsCredentialsProviderChain.of(
            EnvironmentAwsCredentialsProvider.create(environment),
            DefaultCredentialsProvider.create()
    );
}

`
When using STS to assume role with services running in Kuberenets, things works ok in the beginning, but after an hour I see the same issues of connection pool. Seems to be the same error as in this ticket and aws/aws-sdk-java#1282 and #4386
Any solution? This ticket seems to keep getting closed without solutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.
Projects
None yet
Development

No branches or pull requests

4 participants