Skip to content

Apache Lucene open-source search software

LUCENE-6381: defensively wait for a limited time during DWPT stall

Michael McCandlessac0eca6254a5
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index a9805a96fd7..f4896bda4fa 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -52,6 +52,7 @@ Bug Fixes
* LUCENE-6378: Fix all RuntimeExceptions to throw the underlying root cause.
(Varun Thacker, Adrien Grand, Mike McCandless)
+
======================= Lucene 5.1.0 =======================
New Features
@@ -109,6 +110,10 @@ Bug Fixes
toString method of IndexInputs confess when they are from a compound
file. (Robert Muir, Mike McCandless)
+* LUCENE-6381: Add defensive wait time limit in
+ DocumentsWriterStallControl to prevent hangs during indexing if we
+ miss a .notify/All somewhere (Mike McCandless)
+
Optimizations
* LUCENE-6183, LUCENE-5647: Avoid recompressing stored fields
diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java
index c83813bafcb..8ecd483a96a 100644
--- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java
+++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterStallControl.java
@@ -77,7 +77,9 @@ final class DocumentsWriterStallControl {
// don't loop here, higher level logic will re-stall!
try {
incWaiters();
- wait();
+ // Defensive, in case we have a concurrency bug that fails to .notify/All our thread:
+ // just wait for up to 1 second here, and let caller re-stall if it's still needed:
+ wait(1000);
decrWaiters();
} catch (InterruptedException e) {
throw new ThreadInterruptedException(e);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterStallControl.java b/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterStallControl.java
index c656965848a..d7a85fde505 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterStallControl.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocumentsWriterStallControl.java
@@ -46,7 +46,7 @@ public class TestDocumentsWriterStallControl extends LuceneTestCase {
ctrl.updateStalled(true);
waitThreads = waitThreads(atLeast(1), ctrl);
start(waitThreads);
- awaitState(Thread.State.WAITING, waitThreads);
+ awaitState(Thread.State.TIMED_WAITING, waitThreads);
assertTrue(ctrl.hasBlocked());
assertTrue(ctrl.anyStalledThreads());
ctrl.updateStalled(false);