Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

fix test thread safety issue

Michael McCandless64549e4332ff
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 {