Skip to content

Commit 373e9b1

Browse files
authored
Ensure S3Service is STARTED when creating client (#128026) (#128027)
It's possible for another component to request a S3 client after the node has started to shut down, and today the `S3Service` will dutifully attempt to create a fresh client instance even if it is closed. Such clients will then leak, resulting in test failures. With this commit we refuse to create new S3 clients once the service has started to shut down.
1 parent c2c6105 commit 373e9b1

File tree

1 file changed

+8
-0
lines changed
  • modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3

1 file changed

+8
-0
lines changed

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Service.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.http.conn.DnsResolver;
3838
import org.apache.logging.log4j.LogManager;
3939
import org.apache.logging.log4j.Logger;
40+
import org.apache.lucene.store.AlreadyClosedException;
4041
import org.elasticsearch.ElasticsearchException;
4142
import org.elasticsearch.cluster.coordination.stateless.StoreHeartbeatService;
4243
import org.elasticsearch.cluster.metadata.RepositoryMetadata;
@@ -177,6 +178,13 @@ public AmazonS3Reference client(RepositoryMetadata repositoryMetadata) {
177178
if (existing != null && existing.tryIncRef()) {
178179
return existing;
179180
}
181+
182+
if (lifecycle.started() == false) {
183+
// doClose() calls releaseCachedClients() which is also synchronized (this) so if we're STARTED here then the client we
184+
// create will definitely not leak on close.
185+
throw new AlreadyClosedException("S3Service is in state [" + lifecycle + "]");
186+
}
187+
180188
final SdkHttpClient httpClient = buildHttpClient(clientSettings, getCustomDnsResolver());
181189
Releasable toRelease = httpClient::close;
182190
try {

0 commit comments

Comments
 (0)