Skip to content

Commit ef3dcac

Browse files
committed
Fix deadlock in SearchPhaseControllerTests cancellation tests
The cancellation tests could deadlock when threads are delayed by OS scheduling. If cancellation triggers before all threads start, late threads may hit a code path where batchReduceSize causes the latch callback to be deferred to a MergeTask. Under certain timing conditions, these callbacks never execute, causing latch.await() to hang indefinitely. Ensure latch.countDown() is always called by wrapping consumeResult in try-catch. This guarantees test completion regardless of cancellation timing or exceptions. Fixes opensearch-project#19094 Signed-off-by: Atri Sharma <atri.jiit@gmail.com>
1 parent f2a664a commit ef3dcac

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

server/src/test/java/org/opensearch/action/search/SearchPhaseControllerTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,13 @@ private static void consumeShardLevelQueryPhaseResultsAsync(int expectedNumResul
18261826
result.setShardIndex(index);
18271827
result.size(1);
18281828

1829-
consumer.consumeResult(result, latch::countDown);
1829+
try {
1830+
consumer.consumeResult(result, latch::countDown);
1831+
} catch (Exception e) {
1832+
// Ensure latch counts down even on cancellation
1833+
latch.countDown();
1834+
// Don't rethrow - let the thread complete normally
1835+
}
18301836
});
18311837
threads[index].start();
18321838
}

0 commit comments

Comments
 (0)