From 59d54f36cca5d68d60ab30b7e5b3151342dd0ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20H=C3=B8ydahl?= Date: Fri, 24 Apr 2026 23:38:36 +0200 Subject: [PATCH] SOLR-18174 Fix test race condition failure in AsyncTrackerSemaphoreLeakTest --- .../component/AsyncTrackerSemaphoreLeakTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/solr/core/src/test/org/apache/solr/handler/component/AsyncTrackerSemaphoreLeakTest.java b/solr/core/src/test/org/apache/solr/handler/component/AsyncTrackerSemaphoreLeakTest.java index 1ff3ec542ed..fb04ec1ef67 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/AsyncTrackerSemaphoreLeakTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/AsyncTrackerSemaphoreLeakTest.java @@ -204,7 +204,16 @@ public void testSemaphoreLeakOnLBRetry() throws Exception { + " fires synchronously on the IO thread before onComplete can release()."); } - int permitsAfterFailures = testClient.asyncTrackerAvailablePermits(); + // Poll briefly: apiFutures complete on the executor thread, but completeListener fires on + // Jetty's IO thread after response listeners, so allOf().get() can race ahead of release(). + int permitsAfterFailures; + long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5); + do { + permitsAfterFailures = testClient.asyncTrackerAvailablePermits(); + if (permitsAfterFailures == MAX_PERMITS) break; + //noinspection BusyWait + Thread.sleep(10); + } while (System.nanoTime() < deadline); log.info("Permits after retries: {}/{}", permitsAfterFailures, MAX_PERMITS); assertEquals( "All permits should be restored after retries complete",