This is an automated email from the ASF dual-hosted git repository. markt-asf pushed a commit to branch 11.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 5756d17031c7e08726cdd226fee3342f63d625fb Author: Mark Thomas <[email protected]> AuthorDate: Wed Dec 2 21:02:45 2026 +0000 Do not fail the sendfile tests if the write finishes before the stream is checked Three sendfile tests asserted that the stream was not recycled once the clean-up had been deferred until the write finished. The write can finish, and the stream be recycled, between the test seeing that the clean-up was deferred and the assertion, so the assertion failed intermittently, mainly under load. Once the write has finished the stream may be recycled at any time. A write only goes from pending to finished so check that the stream is recycled first and only then that the write is no longer pending. That fails only if the stream was recycled while the write was pending. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --- test/org/apache/coyote/http2/TestHttp2Sendfile.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/test/org/apache/coyote/http2/TestHttp2Sendfile.java b/test/org/apache/coyote/http2/TestHttp2Sendfile.java index 99c68d0d3c..5a1025fb2c 100644 --- a/test/org/apache/coyote/http2/TestHttp2Sendfile.java +++ b/test/org/apache/coyote/http2/TestHttp2Sendfile.java @@ -421,7 +421,7 @@ public class TestHttp2Sendfile extends Http2TestBase { */ 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()); + assertNotRecycledWhileWritePending(stream, processor); } // Read again so that the pending write finishes @@ -463,7 +463,7 @@ public class TestHttp2Sendfile extends Http2TestBase { // The write is still pending so the stream must still be open, active and not recycled Assert.assertTrue(stream.isActive()); Assert.assertTrue(processor.isSendfileCleanupDeferred()); - Assert.assertFalse("The stream was recycled while a sendfile write was pending", stream.isRecycled()); + assertNotRecycledWhileWritePending(stream, processor); Assert.assertSame("The stream was closed while a sendfile write was pending", stream, handler.getStream(3)); // Read the whole response. The stream must not be reset before it has been written. @@ -578,13 +578,26 @@ public class TestHttp2Sendfile extends Http2TestBase { */ 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()); + assertNotRecycledWhileWritePending(stream, processor); } closeConnectionAndCheckCleanUp(stream); } + /* + * Once the write has finished the stream may be recycled at any time, so a stream that is seen to be recycled is + * only a failure if the write is still pending afterwards. The write can only go from pending to finished so, if it + * is pending after the stream was seen to be recycled, it was pending when the stream was recycled. + */ + private void assertNotRecycledWhileWritePending(Stream stream, StreamProcessor processor) { + if (stream.isRecycled()) { + Assert.assertFalse("The stream was recycled while a sendfile write was pending", + processor.isSendfilePending()); + } + } + + /* * 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. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
