[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
This commit is contained in:
Lee Hinman 2018-02-13 12:11:15 -07:00
parent 53d1cde7bc
commit 7c201a64b5
1 changed files with 8 additions and 3 deletions

View File

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