Skip to content

Commit

Permalink
ignore unrecoverable ClosedChannelException errors (#7246)
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Apr 28, 2022
1 parent eec151b commit c351598
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -353,6 +353,16 @@ private HttpToHttp2ConnectionHandler newHttpToHttp2ConnectionHandler() {
*/
void configureForAlpn() {
pipeline.addLast(new ApplicationProtocolNegotiationHandler(server.getServerConfiguration().getFallbackProtocol()) {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (routingInBoundHandler.isIgnorable(cause)) {
// just abandon ship, nothing can be done here to recover
ctx.close();
} else {
super.exceptionCaught(ctx, cause);
}
}

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof SslHandshakeCompletionEvent) {
Expand Down
Expand Up @@ -1419,7 +1419,15 @@ private ByteBuf encodeBodyAsByteBuf(
return byteBuf;
}

private boolean isIgnorable(Throwable cause) {
/**
* Is the exception ignorable by Micronaut.
* @param cause The cause
* @return True if it can be ignored.
*/
protected boolean isIgnorable(Throwable cause) {
if (cause instanceof ClosedChannelException || cause.getCause() instanceof ClosedChannelException) {
return true;
}
String message = cause.getMessage();
return cause instanceof IOException && message != null && IGNORABLE_ERROR_MESSAGE.matcher(message).matches();
}
Expand Down

0 comments on commit c351598

Please sign in to comment.