Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore unrecoverable ClosedChannelException errors #7246

Merged
merged 1 commit into from Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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