RequestContextFilter
sets some thread-locals in holders to bind the request scope to the current servlet request.
Upon returning from doFilterInternal
, it takes care to both clear the thread locals as well as mark the request attributes as completed.
After the request attributes are completed, no further access to the attributes is possible - it throws an exception.
We upgraded one of our Servlet filters further down the chain from RequestContextFilter from a classic synchronous filter to a new asynchronous filter. This means that when our doFilter
returns, it returns all the way up through the RequestContextFilter
back to the container. However, the request is not yet completed - later on, our filter calls resume
. Our filter takes care to save and restore the RequestContextHolder
appropriately, to propagate the Spring request scope. From there our Servlet gets called, it tries to access the request scope, and encounters a fatal error, because it is marked as complete.
It seems that in the case of async filters, the request context filter should not finish the request attributes immediately. Instead it should defer marking it as complete until the async processing finishes.
Comment From: rstoyanchev
RequestContextFilter
is designed to work with async requests. Upon exit from the initial REQUEST dispatch, the Servlet container thread is released and may/will be re-used for other requests, and therefore any ThreadLocal
values must be cleared at that point as the thread is no longer ours. Later when the async work is done, and AsyncContext#dispatch
is called, the Servlet container starts an ASYNC dispatch, the RequestContextFilter
gets involved again, and it re-establishes the RequestContext
. Same for an ERROR dispatch as well.
I don't know what API you are referring to with resume
. It's also not clear why your filter saves the RequestContext
, whether by design, or as a workaround. So the scenario is unclear, but in any case RequestContextFilter
works as it does by design.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.