aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

A question about AWSKMS shutdown function

Open isaac33zhang opened this issue 2 years ago • 1 comments

Describe the issue

The AWSKMS has this shutdown function: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/kms/AWSKMS.html#shutdown-- which "Shuts down this client object, releasing any resources that might be held open". What resources are included? If I have a AWSKMS client built with STSAssumeRoleSessionCredentialsProvider which opens a background thread to refresh credentials, does the shutdown function in AWSKMS close this thread? Thanks!

Links

https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/kms/AWSKMS.html#shutdown--

isaac33zhang avatar Sep 21 '23 23:09 isaac33zhang

Hi @isaac33zhang, I'm sorry for taking so long to reply.

According to the STSAssumeRoleSessionCredentialsProvider Javadoc, when the credentials provider is no longer used the background thread can be shut down via the close() method, which closes its refreashableTask - https://github.com/aws/aws-sdk-java/blob/dbe095458104406605c081a13dc5aec734095ec9/aws-java-sdk-sts/src/main/java/com/amazonaws/auth/STSAssumeRoleSessionCredentialsProvider.java#L364-L371

After a very quick look at the Client shutdown code, I couldn't find anything that would close that refreshableTask. So I recommend to use STSAssumeRoleSessionCredentialsProvider#close if you want to be sure the thread is shutdown.

debora-ito avatar Jun 27 '24 18:06 debora-ito

Hi @debora-ito Following up on your response, I have a couple questions:

  • Could it be considered a potential AWS SDK issue that AwsKmsClient.close() doesn't properly close the refreshableTask?
  • What's the recommended approach for managing AwsKmsClient instances in multi-threaded environments while ensuring all resources are properly closed? Does this mean we can't cache AwsKmsClient under any circumstances?

Would appreciate your insights.

Xiaohan-Qin avatar Jul 03 '24 21:07 Xiaohan-Qin