Skip to content

Commit

Permalink
Try to make tomcat async servlet exception test less flaky (#4772)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Dec 2, 2021
1 parent 32d5ffd commit bbb5717
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ class TestServlet3 {
break
case EXCEPTION:
resp.status = endpoint.status
resp.writer.print(endpoint.body)
def writer = resp.writer
writer.print(endpoint.body)
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()
}
throw new ServletException(endpoint.body)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ class TestServlet5 {
break
case EXCEPTION:
resp.status = endpoint.status
resp.writer.print(endpoint.body)
def writer = resp.writer
writer.print(endpoint.body)
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()
}
throw new ServletException(endpoint.body)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class AsyncServlet extends HttpServlet {
resp.writer.print(endpoint.body)
break
case EXCEPTION:
resp.status = endpoint.status
def writer = resp.writer
writer.print(endpoint.body)
writer.close()
throw new ServletException(endpoint.body)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class AsyncServlet extends AbstractHttpServlet {
break
case EXCEPTION:
resp.status = endpoint.status
resp.writer.print(endpoint.body)
def writer = resp.writer
writer.print(endpoint.body)
writer.close()
throw new ServletException(endpoint.body)
}
}
Expand Down

0 comments on commit bbb5717

Please sign in to comment.