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 4dddafd8b5 Check the clean-up for either order of events in the second
sendfile reset test
4dddafd8b5 is described below
commit 4dddafd8b5f6516418c7a5025006ea45ca3c6feb
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Dec 2 14:51:03 2026 +0000
Check the clean-up for either order of events in the second sendfile reset
test
After the client resets the stream, the event for the reset is usually
processed
while the sendfile write is still pending, which defers the clean-up. If the
write that is in progress completes first, it abandons the operation and
performs the clean-up itself. The test only allowed for the first order so
it
failed intermittently while waiting for the deferral. Accept either order.
If
the write finished first, check that the stream was cleaned up once, that
the
request and response were returned to the pool exactly once and that the
request
was counted once. Closing the connection afterwards must not change that.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
.../org/apache/coyote/http2/TestHttp2Sendfile.java | 48 +++++++++++++++++++---
1 file changed, 43 insertions(+), 5 deletions(-)
diff --git a/test/org/apache/coyote/http2/TestHttp2Sendfile.java
b/test/org/apache/coyote/http2/TestHttp2Sendfile.java
index 8820582cab..26c16d7d2b 100644
--- a/test/org/apache/coyote/http2/TestHttp2Sendfile.java
+++ b/test/org/apache/coyote/http2/TestHttp2Sendfile.java
@@ -562,15 +562,53 @@ public class TestHttp2Sendfile extends Http2TestBase {
StreamProcessor processor = awaitSendfileStalled(stream);
sendRst(3, Http2Error.CANCEL.getCode());
- // The clean-up is deferred until the write finishes
- waitFor("The clean-up was not deferred",
processor::isSendfileCleanupDeferred);
- Assert.assertFalse("The stream was recycled while a sendfile write was
pending", stream.isRecycled());
+ /*
+ * The reset is processed in one of two orders, both of which are
valid. Usually the event for the reset is
+ * processed while the write is still pending and the clean-up is
deferred until the write finishes. If the
+ * write that is in progress completes first it finds that the stream
has been reset, abandons the operation and
+ * performs the clean-up itself.
+ */
+ waitFor("The reset was not processed", () ->
processor.isSendfileCleanupDeferred() || stream.isRecycled());
+ if (processor.isSendfileCleanupDeferred()) {
+ Assert.assertFalse("The stream was recycled while a sendfile write
was pending", stream.isRecycled());
+ }
+
+ closeConnectionAndCheckCleanUp(stream);
+ }
+
+ /*
+ * Closes the connection once the reset has been processed and checks that
the stream was cleaned up once. What
+ * happens to the request and response depends on which of the two orders
occurred.
+ */
+ private void closeConnectionAndCheckCleanUp(Stream stream) throws
Exception {
+ // Decide which order occurred before closing the connection. Once the
stream is recycled, it can't change.
+ boolean writeFinishedFirst = stream.isRecycled();
+ if (writeFinishedFirst) {
+ waitFor("The clean-up did not complete",
stream::isRecycleComplete);
+ }
+
+ // Closing the connection must not clean up the stream again
handler.close();
Assert.assertEquals("Stream that was not recycled", 0,
countNotRecycled(Collections.singletonList(stream)));
- Assert.assertNotSame("The request was returned to the pool",
stream.getCoyoteRequest(),
- http2Protocol.popRequestAndResponse());
+ org.apache.coyote.Request request = stream.getCoyoteRequest();
+ if (writeFinishedFirst) {
+ // The write finished first and the connection was still open so
the request and response were re-used...
+ Assert.assertSame("The request was not returned to the pool",
request,
+ http2Protocol.popRequestAndResponse());
+ // ...but only once
+ Assert.assertNotSame("The request was returned to the pool more
than once", request,
+ http2Protocol.popRequestAndResponse());
+ Assert.assertEquals("Each request must be counted once", 2,
http2Protocol.getGlobal().getRequestCount());
+ } else {
+ /*
+ * The connection was closed while the write was pending. A
callback for the write may still be running and
+ * using the request and response so they must not be re-used.
+ */
+ Assert.assertNotSame("The request was returned to the pool",
request,
+ http2Protocol.popRequestAndResponse());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]