This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 98acd9c191 Fix race in AsyncContext dispatch failure tests
98acd9c191 is described below
commit 98acd9c191c047d3ec781f569157b0246176f0d5
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Nov 30 11:48:39 2026 +0000
Fix race in AsyncContext dispatch failure tests
The client can receive the response before the container thread calls
AsyncListener.onError(). Wait for onComplete(), which is called after
onError(), before checking what the listeners received. Without this,
testAsyncDispatchNoArgFailureNonContainerThread can fail intermittently
and the second listener test can pass without the listener having run.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
test/org/apache/catalina/core/TestAsyncContextImpl.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/test/org/apache/catalina/core/TestAsyncContextImpl.java
b/test/org/apache/catalina/core/TestAsyncContextImpl.java
index 5c09292b82..073afa0a6a 100644
--- a/test/org/apache/catalina/core/TestAsyncContextImpl.java
+++ b/test/org/apache/catalina/core/TestAsyncContextImpl.java
@@ -2601,13 +2601,17 @@ public class TestAsyncContextImpl extends
TomcatBaseTest {
Assert.assertTrue("Request waited for the async timeout: " + elapsed +
"ms", elapsed < 5000);
Assert.assertTrue("The caller must be told about the failure",
servlet.callerException.get() instanceof
UnsupportedOperationException);
+ /*
+ * The client can receive the response before the container thread
calls onError() so wait for onComplete(),
+ * which is called after onError(), before checking what onError()
received.
+ */
+ Assert.assertTrue("onComplete() must be called",
servlet.completed.await(5, TimeUnit.SECONDS));
// The failure is handled like any other failure of an async dispatch
so may be wrapped
Throwable listenerThrowable = servlet.listenerThrowable.get();
while (listenerThrowable != null && !(listenerThrowable instanceof
UnsupportedOperationException)) {
listenerThrowable = listenerThrowable.getCause();
}
Assert.assertNotNull("onError() must be called with the failure",
listenerThrowable);
- Assert.assertTrue("onComplete() must be called",
servlet.completed.await(5, TimeUnit.SECONDS));
}
@@ -2668,9 +2672,13 @@ public class TestAsyncContextImpl extends TomcatBaseTest
{
long elapsed = doTestAsyncDispatchNoArgFailure(servlet, null,
responseBody);
Assert.assertTrue("Request waited for the async timeout: " + elapsed +
"ms", elapsed < 5000);
+ /*
+ * The client can receive the response before the container thread
calls the listeners so wait for onComplete(),
+ * which is called after onError(), before checking what the second
listener's onError() did.
+ */
+ Assert.assertTrue("onComplete() must be called",
servlet.completed.await(5, TimeUnit.SECONDS));
Assert.assertNull("The second listener must be able to use the
AsyncContext",
servlet.secondListenerException.get());
- Assert.assertTrue("onComplete() must be called",
servlet.completed.await(5, TimeUnit.SECONDS));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]