From 64549e4332ffe631a1586fb9a16a3ce72a0ccd79 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 27 Aug 2012 15:20:17 +0000 Subject: [PATCH] fix test thread safety issue git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1377711 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/search/ShardSearchingTestBase.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java b/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java index e99f02d9cca..cf7ca0d6174 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java @@ -468,15 +468,17 @@ public abstract class ShardSearchingTestBase extends LuceneTestCase { // Get the current (fresh) searcher for this node public ShardIndexSearcher acquire() { - final ShardIndexSearcher s = currentShardSearcher; - // TODO: this isn't thread safe.... in theory the - // reader could get decRef'd to 0 before we have a - // chance to incRef, ie if a reopen happens right - // after the above line, this thread gets stalled, and - // the old IR is closed. But because we use SLM in - // this test, this will be exceptionally rare: - s.getIndexReader().incRef(); - return s; + while(true) { + final ShardIndexSearcher s = currentShardSearcher; + // In theory the reader could get decRef'd to 0 + // before we have a chance to incRef, ie if a reopen + // happens right after the above line, this thread + // gets stalled, and the old IR is closed. So we + // must try/retry until incRef succeeds: + if (s.getIndexReader().tryIncRef()) { + return s; + } + } } public void release(ShardIndexSearcher s) throws IOException {