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
Warn against direct usage of Servlet API in WebFlux applications #28872
Comments
@mwisnicki I’ll look into skipping the optimization in this case. In the meantime, I think using a ˋWebFilter` instead for this will be much more efficient as you’ll keep the optimization. We’ve measured the performance improvement of this one and it’s not negligible. Is your filter doing anything else or just adding a header? |
This was just a minimal reproducible test case. Unfortunately I have no control over actual servlet code :( |
Then you should make sure that the filter does not perform blocking operations (like an HTTP client fetching a token synchronously) or is not reading/writing to the request or response with the blocking Servlet APIs. This would completely defeat the runtime benefits of WebFlux. |
Generally speaking, the Servlet API is not meant to be used directly in a WebFlux application, and we don't aim to support it. You might run into other similar limitations since the |
While we don't actively support using Servlet Again, using any Servlet Filter with a WebFlux application can lead to production issues as such filters are likely to interfere with the Async IO operations performed by our Servlet reactive bridge. This is now scheduled for 6.1.x. |
After working on this issue, I think that undoing this native adaptation would bring no benefit and would make performance worse for most WebFlux applications. The In this very case, the reporter has I'll turn this issue into a documentation issue - let's improve the message there and underline that one should not interact with Servlet-level contracts in this case as they're likely to face this issue or worse, mix async and blocking I/O code in the same app. |
Affects: 5.x/current
I have a Servlet filter that adds request headers via decorating request object (the only way allowed by Servlet API).
Unfortunately
TomcatServerHttpRequest
/TomcatHeadersAdapter
bypasses request object and reaches directly into backing map thus my wrapper is ignored.Generic
ServletServerHttpRequest
looks to handle it correctly but Tomcat subclass seems to have been too optimized.The text was updated successfully, but these errors were encountered: