Skip to content

Commit

Permalink
[TEST] Synchronize searcher list in IndexShardTests
Browse files Browse the repository at this point in the history
It's possible to check the list size, then attempt to remove a searcher and
throw an IndexOutOfBoundsException due to multiple threads.

Resolves elastic#27651
  • Loading branch information
dakrone committed Feb 13, 2018
1 parent 36d44fa commit 14fd907
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2781,9 +2781,14 @@ public void testSegmentMemoryTrackedWithRandomSearchers() throws Exception {

if (randomBoolean() && searchers.size() > 1) {
// Close one of the searchers at random
Engine.Searcher searcher = searchers.remove(0);
logger.debug("--> {} closing searcher {}", threadName, searcher.source());
IOUtils.close(searcher);
synchronized (searchers) {
// re-check because it could have decremented after the check
if (searchers.size() > 1) {
Engine.Searcher searcher = searchers.remove(0);
logger.debug("--> {} closing searcher {}", threadName, searcher.source());
IOUtils.close(searcher);
}
}
}
} catch (Exception e) {
logger.warn("--> got exception: ", e);
Expand Down

0 comments on commit 14fd907

Please sign in to comment.