Skip to content

Commit

Permalink
#412 Add feature to handle nested client abort exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kagemomiji committed May 15, 2024
1 parent 4bfc6d0 commit bb44863
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ public ModelAndView resolveException(
// This happens often and outside of the control of the server, so
// we catch Tomcat/Jetty "connection aborted by client" exceptions
// and display a short error message.
boolean shouldCatch = Util.isInstanceOfClassName(e, "org.apache.catalina.connector.ClientAbortException")
|| Util.isInstanceOfClassName(e.getCause(), "org.apache.catalina.connector.ClientAbortException");
boolean shouldCatch = isClientAbortException(e);
if (shouldCatch) {
LOG.info("{}: Client unexpectedly closed connection while loading {} ({})", request.getRemoteAddr(), Util.getAnonymizedURLForRequest(request), e.getCause().toString());
LOG.info("{}: Client unexpectedly closed connection while loading {}", request.getRemoteAddr(), Util.getAnonymizedURLForRequest(request));
return null;
}

Expand All @@ -41,4 +40,20 @@ public ModelAndView resolveException(
public int getOrder() {
return Integer.MIN_VALUE;
}

/**
* Check if the exception or any of its causes is a "client abort" exception.
*
* @param e The exception to check
* @return True if the exception or any of its causes is a "client abort" exception
*/
private boolean isClientAbortException(Throwable e) {
if (e == null) {
return false;
}
if (Util.isInstanceOfClassName(e, "org.apache.catalina.connector.ClientAbortException")) {
return true;
}
return isClientAbortException(e.getCause());
}
}

0 comments on commit bb44863

Please sign in to comment.