Skip to content

Commit 7c201a6

Browse files
committed
[TEST] Synchronize searcher list in IndexShardTests
It's possible to check the list size, then attempt to remove a searcher and throw an IndexOutOfBoundsException due to multiple threads. Resolves #27651
1 parent 53d1cde commit 7c201a6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,9 +2926,14 @@ public void testSegmentMemoryTrackedWithRandomSearchers() throws Exception {
29262926

29272927
if (randomBoolean() && searchers.size() > 1) {
29282928
// Close one of the searchers at random
2929-
Engine.Searcher searcher = searchers.remove(0);
2930-
logger.debug("--> {} closing searcher {}", threadName, searcher.source());
2931-
IOUtils.close(searcher);
2929+
synchronized (searchers) {
2930+
// re-check because it could have decremented after the check
2931+
if (searchers.size() > 1) {
2932+
Engine.Searcher searcher = searchers.remove(0);
2933+
logger.debug("--> {} closing searcher {}", threadName, searcher.source());
2934+
IOUtils.close(searcher);
2935+
}
2936+
}
29322937
}
29332938
} catch (Exception e) {
29342939
logger.warn("--> got exception: ", e);

0 commit comments

Comments
 (0)