You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2022/04/28 22:31:13 UTC

[lucene] branch branch_9x updated: LUCENE-10292: prevent thread leak (or test timeout) if exception/assertion failure in test iterator

This is an automated email from the ASF dual-hosted git repository.

hossman pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 115bcd9c66d LUCENE-10292: prevent thread leak (or test timeout) if exception/assertion failure in test iterator
115bcd9c66d is described below

commit 115bcd9c66d9723a7a1ea5131aa2f5d16a6867b7
Author: Chris Hostetter <ho...@apache.org>
AuthorDate: Thu Apr 28 15:17:38 2022 -0700

    LUCENE-10292: prevent thread leak (or test timeout) if exception/assertion failure in test iterator
    
    (cherry picked from commit 6afb9bc25a5935a3cba0a06e67b27fe290255467)
---
 .../lucene/search/suggest/SuggestRebuildTestUtil.java | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/SuggestRebuildTestUtil.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/SuggestRebuildTestUtil.java
index badb6cb0410..44d3282b635 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/SuggestRebuildTestUtil.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/SuggestRebuildTestUtil.java
@@ -71,15 +71,22 @@ public final class SuggestRebuildTestUtil {
                         readyToCheck, readyToAdvance, new InputArrayIterator(data.iterator())));
               } catch (Throwable t) {
                 buildError.set(t);
+                readyToCheck.release(data.size() * 100); // flood the semaphore so we don't block
               }
             });
     rebuilder.start();
     // at every stage of the slow rebuild, we should still be able to get our original suggestions
     // (+1 iteration to ensure final next() call can return null)
     for (int i = 0; i < data.size() + 1; i++) {
-      readyToCheck.acquire();
-      initialChecks.check(suggester);
-      readyToAdvance.release();
+      try {
+        assertNull(buildError.get());
+        readyToCheck.acquire();
+        initialChecks.check(suggester);
+        readyToAdvance.release();
+      } catch (Throwable t) {
+        readyToAdvance.release(data.size() * 100); // flood the semaphore so we don't block
+        throw t;
+      }
     }
     // once all the data is released from the iterator, the background rebuild should finish, and
     // suggest results
@@ -119,7 +126,11 @@ public final class SuggestRebuildTestUtil {
     @Override
     public BytesRef next() throws IOException {
       releaseOnNext.release();
-      acquireOnNext.acquireUninterruptibly();
+      try {
+        acquireOnNext.acquire();
+      } catch (InterruptedException e) {
+        throw new RuntimeException(e);
+      }
       return inner.next();
     }