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

As discussed with @chemicL, this is a limitation of the current design which is using a WebFilter. The exception handling mechanism is applied with ExceptionHandlingWebHandler, which is a HttpHandlerDecorator. WebFilter instances are applied at a higher level and are not aware of this. #31303

Closed
kasra-haghpanah opened this issue Sep 23, 2023 · 7 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@kasra-haghpanah
Copy link

          As discussed with @chemicL, this is a limitation of the current design which is using a `WebFilter`. The exception handling mechanism is applied with `ExceptionHandlingWebHandler`, which is a `HttpHandlerDecorator`. `WebFilter` instances are applied at a higher level and are not aware of this.

This limitation is serious enough that I'm considering this a bug and should be fixed in 6.0.x. A possible solution would be to reimplement the instrumentation as a HttpHandlerDecorator itself, but this needs to validated. I'm scheduling this issue for 6.0.x but this can be revisited depending on our findings with HttpHandlerDecorator. As a result, the existing WebFilter should be deprecated.

Originally posted by @bclozel in #30013 (comment)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 23, 2023
@kasra-haghpanah
Copy link
Author

Recently, I've been programming Spring Webflux On the 3.1.4 version. I've also used Spring Security and the type of the token is JWT. If the token is not valid, the Security Class will throw an exception. Although the throw goes through the ErrorWebExceptionHandler Class, it does not arrive in the WebFilter Class. This issue just happens when an exception in the Security Class, but in the rest of the cases, it works correctly.
The following link is the address of my project:
https://github.com/kasra-haghpanah/spring-rsocket-with-rsocketjs
The lists of classes that are related to the problem, including Filter, GlobalErrorHandler, and SecurityConfig in my project.

@bclozel
Copy link
Member

bclozel commented Sep 24, 2023

#30013 has been fixed. What is the purpose of this issue?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Sep 24, 2023
@kasra-haghpanah
Copy link
Author

I use WebFilter for making general Exceptions and Logging for Logstash in the WebFilter layer. It just does not work correctly in the Security Level means that the Security Class throws an Exception and WebFilter can not Catch it in the doOnError Method, but it works correctly in other cases.

@kasra-haghpanah
Copy link
Author

I use WebFilter for making general Exception Handlings and Logging for Logstash in the WebFilter layer. It just does not work correctly in the Security Level means that the Security Class throws an Exception and WebFilter can not Catch it in the doOnError Method, but it works correctly in other cases.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Sep 24, 2023
@bclozel
Copy link
Member

bclozel commented Sep 24, 2023

The WebFilter level was the wrong level for instrumentation. We have fixed that in #30013 already. Did you check with the latest milestones?

I'm closing this issue as there is nothing actionable here.

@bclozel bclozel added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Sep 24, 2023
@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2023
@kasra-haghpanah
Copy link
Author

According to the following code in my WebFilter level, I expect after each request, if there is an exception, the doOnError Method will catch it, but if I throw an exception in Security levels does not work truly at least for me on my project. Of course, In other cases works correctly. On the other hand, according to #30013, it was told "this is a limitation of the current design which is using a WebFilter. The exception handling mechanism is applied with ExceptionHandlingWebHandler, which is a HttpHandlerDecorator. WebFilter instances are applied at a higher level and are not aware of this."
Ok, thank you so much.

@OverRide
public Mono filter(ServerWebExchange exchange, WebFilterChain webFilterChain) {

return webFilterChain.filter(exchangeDecorator)
.doOnSuccess(aVoid -> {

            })
            .doAfterTerminate(() -> {
                // System.out.println("doAfterTerminate");
            })
            .doOnError(throwable -> {
                // my exception handlings
           })
           .doFinally(signalType -> {
          });

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants