Skip to content

Commit 794a33a

Browse files
authored
Gracefully tear down S3BlobContainerRetriesTests (#18144)
I believe the test tear down is racing with the thread leak detector because the `shutdown()` method does not actually wait for all the threads to stop. The fix here is to use `ThreadPool::terminate` which does the proper shutdown and ensures are threads are stopped before returning from the tearDown method. Signed-off-by: Andrew Ross <andrross@amazon.com>
1 parent a6724d3 commit 794a33a

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

plugins/repository-s3/src/test/java/org/opensearch/repositories/s3/S3BlobContainerRetriesTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.opensearch.repositories.s3.async.AsyncTransferManager;
7070
import org.opensearch.repositories.s3.async.SizeBasedBlockingQ;
7171
import org.opensearch.repositories.s3.async.TransferSemaphoresHolder;
72+
import org.opensearch.threadpool.ThreadPool;
7273
import org.junit.After;
7374
import org.junit.Assert;
7475
import org.junit.Before;
@@ -94,6 +95,7 @@
9495
import java.util.concurrent.TimeUnit;
9596
import java.util.concurrent.atomic.AtomicInteger;
9697
import java.util.concurrent.atomic.AtomicReference;
98+
import java.util.stream.Stream;
9799

98100
import static org.opensearch.repositories.s3.S3ClientSettings.DISABLE_CHUNKED_ENCODING;
99101
import static org.opensearch.repositories.s3.S3ClientSettings.ENDPOINT_SETTING;
@@ -162,14 +164,10 @@ public void setUp() throws Exception {
162164
@After
163165
public void tearDown() throws Exception {
164166
IOUtils.close(service, asyncService);
165-
166-
streamReaderService.shutdown();
167-
futureCompletionService.shutdown();
168-
remoteTransferRetry.shutdown();
169-
transferQueueConsumerService.shutdown();
170-
scheduler.shutdown();
171167
normalPrioritySizeBasedBlockingQ.close();
172168
lowPrioritySizeBasedBlockingQ.close();
169+
Stream.of(streamReaderService, futureCompletionService, remoteTransferRetry, transferQueueConsumerService, scheduler)
170+
.forEach(e -> assertTrue(ThreadPool.terminate(e, 5, TimeUnit.SECONDS)));
173171
IOUtils.close(transferNIOGroup);
174172

175173
if (previousOpenSearchPathConf != null) {

0 commit comments

Comments
 (0)