Skip to content

Commit

Permalink
Add missing exception name to DisconnectedClientHelper
Browse files Browse the repository at this point in the history
Closes gh-31717
  • Loading branch information
rstoyanchev committed Nov 30, 2023
1 parent 9ade52d commit 8ca8212
Showing 1 changed file with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class DisconnectedClientHelper {
Set.of("broken pipe", "connection reset by peer");

private static final Set<String> EXCEPTION_TYPE_NAMES =
Set.of("ClientAbortException", "EOFException", "EofException");

Set.of("AbortedException", "ClientAbortException", "EOFException", "EofException");

private final Log logger;

Expand All @@ -51,6 +50,26 @@ public DisconnectedClientHelper(String logCategory) {
}


/**
* Check via {@link #isClientDisconnectedException} if the exception
* indicates the remote client disconnected, and if so log a single line
* message when DEBUG is on, and a full stacktrace when TRACE is on for
* the configured logger.
*/
public boolean checkAndLogClientDisconnectedException(Throwable ex) {
if (isClientDisconnectedException(ex)) {
if (logger.isTraceEnabled()) {
logger.trace("Looks like the client has gone away", ex);
}
else if (logger.isDebugEnabled()) {
logger.debug("Looks like the client has gone away: " + ex +
" (For a full stack trace, set the log category '" + logger + "' to TRACE level.)");
}
return true;
}
return false;
}

/**
* Whether the given exception indicates the client has gone away.
* Known cases covered:
Expand All @@ -60,7 +79,7 @@ public DisconnectedClientHelper(String logCategory) {
* <li>IOException "Broken pipe" or "connection reset by peer"
* </ul>
*/
public boolean isClientDisconnectedException(Throwable ex) {
public static boolean isClientDisconnectedException(Throwable ex) {
String message = NestedExceptionUtils.getMostSpecificCause(ex).getMessage();
if (message != null) {
String text = message.toLowerCase();
Expand All @@ -73,24 +92,4 @@ public boolean isClientDisconnectedException(Throwable ex) {
return EXCEPTION_TYPE_NAMES.contains(ex.getClass().getSimpleName());
}

/**
* Check via {@link #isClientDisconnectedException} if the exception
* indicates the remote client disconnected, and if so log a single line
* message when DEBUG is on, and a full stacktrace when TRACE is on for
* the configured logger.
*/
public boolean checkAndLogClientDisconnectedException(Throwable ex) {
if (isClientDisconnectedException(ex)) {
if (logger.isTraceEnabled()) {
logger.trace("Looks like the client has gone away", ex);
}
else if (logger.isDebugEnabled()) {
logger.debug("Looks like the client has gone away: " + ex +
" (For a full stack trace, set the log category '" + logger + "' to TRACE level.)");
}
return true;
}
return false;
}

}

0 comments on commit 8ca8212

Please sign in to comment.