Skip to content

Commit ca21d22

Browse files
Fix SearchableSnapshotDirectoryTests Leaking Listeners (#64150) (#64155)
We need to make sure we don't shut down the pool while ref count release operations are enqueued but not yet executing.
1 parent 9a690cd commit ca21d22

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryTests.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import org.elasticsearch.test.IndexSettingsModule;
9393
import org.elasticsearch.threadpool.TestThreadPool;
9494
import org.elasticsearch.threadpool.ThreadPool;
95+
import org.elasticsearch.threadpool.ThreadPoolStats;
9596
import org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots;
9697
import org.elasticsearch.xpack.searchablesnapshots.cache.CacheService;
9798
import org.hamcrest.Matcher;
@@ -119,6 +120,7 @@
119120
import java.util.List;
120121
import java.util.Map;
121122
import java.util.Set;
123+
import java.util.concurrent.TimeUnit;
122124
import java.util.stream.Collectors;
123125

124126
import static java.util.Arrays.asList;
@@ -627,7 +629,7 @@ protected void assertSnapshotOrGenericThread() {
627629
Releasables.close(releasables);
628630
}
629631
} finally {
630-
terminate(threadPool);
632+
terminateSafely(threadPool);
631633
}
632634
}
633635

@@ -744,7 +746,7 @@ public void testClearCache() throws Exception {
744746
}
745747
}
746748
} finally {
747-
terminate(threadPool);
749+
terminateSafely(threadPool);
748750
}
749751
}
750752
}
@@ -940,6 +942,17 @@ private SearchableSnapshotRecoveryState createRecoveryState() {
940942
return recoveryState;
941943
}
942944

945+
// Wait for all operations on the threadpool to complete to make sure we don't leak any reference count releasing and then shut it down
946+
private static void terminateSafely(ThreadPool threadPool) throws Exception {
947+
assertBusy(() -> {
948+
for (ThreadPoolStats.Stats stat : threadPool.stats()) {
949+
assertEquals(stat.getActive(), 0);
950+
assertEquals(stat.getQueue(), 0);
951+
}
952+
});
953+
assertTrue(ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS));
954+
}
955+
943956
private static class FaultyReadsFileSystem extends FilterFileSystemProvider {
944957
FaultyReadsFileSystem(FileSystem inner) {
945958
super("faulty_fs://", inner);
@@ -956,5 +969,4 @@ public int read(ByteBuffer dst) throws IOException {
956969
};
957970
}
958971
}
959-
960972
}

0 commit comments

Comments
 (0)