File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3 Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -158,10 +158,16 @@ public AmazonS3Reference client(RepositoryMetadata repositoryMetadata) {
158158 }
159159 // TODO NOMERGE: consider alternative methods of retaining an httpClient reference for an explicit close() call.
160160 SdkHttpClient httpClient = buildHttpClient (clientSettings );
161- final AmazonS3Reference clientReference = new AmazonS3Reference (buildClient (clientSettings , httpClient ), httpClient );
162- clientReference .mustIncRef ();
163- clientsCache = Maps .copyMapWithAddedEntry (clientsCache , clientSettings , clientReference );
164- return clientReference ;
161+ Releasable toRelease = httpClient ::close ;
162+ try {
163+ final AmazonS3Reference clientReference = new AmazonS3Reference (buildClient (clientSettings , httpClient ), httpClient );
164+ clientReference .mustIncRef ();
165+ clientsCache = Maps .copyMapWithAddedEntry (clientsCache , clientSettings , clientReference );
166+ toRelease = null ;
167+ return clientReference ;
168+ } finally {
169+ Releasables .close (toRelease );
170+ }
165171 }
166172 }
167173
You can’t perform that action at this time.
0 commit comments