Skip to content

Commit 0f9c1ea

Browse files
authored
Ensure S3Service is STARTED when creating client (#128026)
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 41613e6 commit 0f9c1ea

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

+8
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;
@@ -176,6 +177,13 @@ public AmazonS3Reference client(RepositoryMetadata repositoryMetadata) {
176177
if (existing != null && existing.tryIncRef()) {
177178
return existing;
178179
}
180+
181+
if (lifecycle.started() == false) {
182+
// doClose() calls releaseCachedClients() which is also synchronized (this) so if we're STARTED here then the client we
183+
// create will definitely not leak on close.
184+
throw new AlreadyClosedException("S3Service is in state [" + lifecycle + "]");
185+
}
186+
179187
final SdkHttpClient httpClient = buildHttpClient(clientSettings, getCustomDnsResolver());
180188
Releasable toRelease = httpClient::close;
181189
try {

0 commit comments

Comments
 (0)