-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
After the change to OncePerRequestFilter in #22989, when using a RequestContextFilter, the request context will no longer be available after sendError(...) completes in Jetty. This means that the usage of any @Scope("request") beans in places like the afterCompletion in interceptors or on the return path of filters will not work, nor will more general usage of RequestContextHolder.getRequestAttributes() work.
The problem is that the change in OncePerRequestFilter causes the filter to be processed again, even though it is a OncePerRequestFilter. And the RequestContextFilter is not designed to be nested. The finally block clears all request attributes, even when attributes were set before the filter started.
I'm not really sure what the best solution would be. Maybe introduce a OncePerRequestFilter.shouldNotFilterOnNestedErrorDispatch() or something. Or maybe make RequestContextFilter restore the previous request context, instead of clearing everything (it seems like FrameworkServlet does this too)? Or both.
Affected version: 5.1.8