Skip to content

Commit f4ac638

Browse files
authored
Reduce flakiness in TomcatServlet5Test.requestWithException() (#18486)
1 parent 61bee80 commit f4ac638

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • instrumentation/servlet/servlet-5.0/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0

instrumentation/servlet/servlet-5.0/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v5_0/TestServlet5.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,14 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
236236
resp.sendError(endpoint.getStatus(), endpoint.getBody());
237237
} else if (EXCEPTION.equals(endpoint)) {
238238
resp.setStatus(endpoint.getStatus());
239-
resp.getWriter().print(endpoint.getBody());
239+
PrintWriter writer = resp.getWriter();
240+
writer.print(endpoint.getBody());
241+
if (req.getClass().getName().contains("catalina")) {
242+
// on tomcat close the writer to ensure response is sent immediately,
243+
// otherwise there is a chance that tomcat resets the connection before the
244+
// response is sent
245+
writer.close();
246+
}
240247
throw new IllegalStateException(endpoint.getBody());
241248
} else if (HTML_PRINT_WRITER.equals(endpoint)) {
242249
// intentionally testing setting status before contentType here to cover that case

0 commit comments

Comments
 (0)