Reduce flakiness in TomcatServlet5Test.requestWithException()#18486
Merged
Conversation
…cat.TomcatServlet5Test.requestWithException()[2] Automated fix attempt based on Develocity flaky-test analysis.
trask
commented
May 1, 2026
Comment on lines
157
to
164
| PrintWriter writer = resp.getWriter(); | ||
| writer.print(endpoint.getBody()); | ||
| if (req.getClass().getName().contains("catalina")) { | ||
| // on tomcat close the writer to ensure response is sent immediately, | ||
| // otherwise there is a chance that tomcat resets the connection before the | ||
| // response is sent | ||
| writer.close(); | ||
| } |
Member
Author
There was a problem hiding this comment.
same fix already exists here
laurit
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automated attempt at fixing flakiness in
io.opentelemetry.instrumentation.servlet.v5_0.tomcat.TomcatServlet5Test.requestWithException()[2].instrumentation/servlet/servlet-5.0/library/src/test/java/io/opentelemetry/instrumentation/servlet/v5_0/tomcat/TomcatServlet5Test.javaRecent failed/flaky scans
:instrumentation:servlet:servlet-5.0:library:test):instrumentation:servlet:servlet-5.0:library:test):instrumentation:servlet:servlet-5.0:library:test):instrumentation:servlet:servlet-5.0:library:test):instrumentation:servlet:servlet-5.0:library:test)Flake history (per UTC day)
Sample failure (from Develocity)
Copilot diagnosis
Flaky Test Fix Diagnosis
Root cause
The
FakeAsyncservlet's EXCEPTION endpoint handler was missing a critical mitigation for Tomcat's connection reset behavior. When the servlet throws an exception after writing a response, Tomcat can reset the connection before the client fully receives the response body, causing the Armeria HTTP client to fail withClosedSessionExceptionduring theaggregate().join()call.Fix
PrintWriter.close()call before throwing the exception inTestServlet5.FakeAsync.EXCEPTIONhandlerAsync.EXCEPTIONhandler (lines 159-164)req.getClass().getName().contains("catalina")to detect Tomcat and close the writer only on that server, ensuring the response is fully flushed before the exception is thrownWhy this addresses the root cause
The explicit
close()call forces Tomcat to flush and commit the response to the network before the exception propagates to the servlet container. Without this, there's a race condition where Tomcat's error handling (triggered by the exception) can reset the connection while the client is still reading the response stream, resulting inClosedSessionExceptionat the client side. TheAsyncservlet already had this mitigation and was not flaky; this fix bringsFakeAsyncto parity.Risks / follow-ups
ClosedSessionException)Asyncservlet since it was introducedReview the diagnosis and the diff carefully before merging - automated fixes can mask flakiness instead of addressing the root cause.