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

[Question/Problem] Cannot capture io.netty.channel.StacklessClosedChannelException #924

Open
SimoneGiusso opened this issue May 17, 2023 · 0 comments

Comments

@SimoneGiusso
Copy link

I have a Spring WebFlux application where sometimes the client closed the connection while the app is writing the response. This cause a io.netty.channel.StacklessClosedChannelException. From the log I see that this is logged as an ERROR by the AdviceTraits.java.

Since I do not want to see this error in the log (which triggers an alert) because is not an application error, it's just a client behaviour that I cannot avoid, I'd like to skip/capture the exception.

I tried to create a custom Trait:

public interface ClosedChannelExceptionAdviceTrait extends AdviceTrait {

    @ExceptionHandler
    default Mono<Void> handleClosedChannel(
        final ServerWebExchange request,
        final ClosedChannelException exception
    ) {
        return Mono.fromRunnable(() -> AdviceTraits.log(exception, BAD_REQUEST));
    }

}

Which is then implemented by my ExceptionHandling:

@ControllerAdvice
class ExceptionHandling implements ProblemHandling, SecurityAdviceTrait, ClosedChannelExceptionAdviceTrait {
    // some code...
}

The problem is that nothing changed, the exception is still logged as an error by the AdviceTraits.

I had the same problem with Spring MVC (here I'm not using this library though) and I resolved by just having this method in my @ControllerAdvice:

    @ExceptionHandler(ClientAbortException.class) // the exception is different because the web engine is not netty
    private void clientAbortException() {
        log.warn("Client closed connection!");
    }

And it works.

While I was able to replicate the error locally in Spring MVC, I didn't find a way to replicate it for Spring WebFlux.

Is there a way to solve this problem without modifying the AdviceTraits.java class (which I cannot do)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant