Skip to content

AWS: Close custom AwsCredentialsProvider in RESTSigV4AuthSession#15818

Open
XJDKC wants to merge 1 commit intoapache:mainfrom
XJDKC:rxing-close-custom-aws-credentials-provider
Open

AWS: Close custom AwsCredentialsProvider in RESTSigV4AuthSession#15818
XJDKC wants to merge 1 commit intoapache:mainfrom
XJDKC:rxing-close-custom-aws-credentials-provider

Conversation

@XJDKC
Copy link
Copy Markdown
Member

@XJDKC XJDKC commented Mar 29, 2026

Summary

RESTSigV4AuthSession holds an AwsCredentialsProvider obtained from AwsProperties.restCredentialsProvider(), which may be AutoCloseable (e.g. DefaultCredentialsProvider, StsCredentialsProvider). Previously, close() only closed the delegate AuthSession but never closed the credentials provider, causing a resource leak.

This PR uses a CloseableGroup to manage both the delegate and the credentials provider (when it implements AutoCloseable), ensuring both are properly closed. Close failures are suppressed so that one failing resource doesn't prevent the other from being closed.

@github-actions github-actions bot added the AWS label Mar 29, 2026
@XJDKC XJDKC changed the title Core: Close custom AwsCredentialsProvider in RESTSigV4AuthSession AWS: Close custom AwsCredentialsProvider in RESTSigV4AuthSession Mar 29, 2026
Comment on lines +315 to +327
AuthSession delegate = Mockito.mock(AuthSession.class);
CloseableAwsCredentialsProvider credentialsProvider =
Mockito.mock(CloseableAwsCredentialsProvider.class);
AwsProperties properties = Mockito.mock(AwsProperties.class);
when(properties.restSigningRegion()).thenReturn(Region.US_WEST_2);
when(properties.restSigningName()).thenReturn("execute-api");
when(properties.restCredentialsProvider()).thenReturn(credentialsProvider);

RESTSigV4AuthSession session = new RESTSigV4AuthSession(signer, delegate, properties);
session.close();

Mockito.verify(delegate).close();
Mockito.verify(credentialsProvider).close();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is lot of common code between this and function below can we extract the common part, i beliver we just need a delegate that throws and a delegate that doesn't in both the test respectively

@Override
public void close() {
delegate.close();
if (closeableGroup != null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

when will this be null ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants