Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty 9.0.4 issue (also in 9.0.5-SNAPSHOT) with Spring MVC Async (test provided)


On Thu, Aug 1, 2013 at 6:07 PM, Rossen Stoyanchev
<rstoyanchev@xxxxxxxxxxxxx> wrote:
> I think the issue starts with request.isAsyncStarted returning false after
> async was started and a dispatch was issued immediately. Now rather than
> exiting the request processing thread, code continues to execute as if async
> did not start. That's going to lead to an exception.
> I can find out what that exception is, if you still want me to, but you
> should be able to easily reproduce what I think is the root cause by calling
> request.startAsync(req,res), then calling asyncContext.dispatch(), and then
> checking if async has started. It returns false instead of true.

I just checked the Servlet specification, and Jetty's behavior is correct.
While this is explicit in Servlet 3.1, I would recommend that Spring
does not rely on isAsyncStarted() because otherwise it will be broken
in any Servlet 3.1 compliant container.

>From the specification (section, page 2-13):
"public boolean isAsyncStarted() - Returns true if async processing has
started on this request, and false otherwise. If this request has been
dispatched using one of the AsyncContext.dispatch methods since it was put
in asynchronous mode, or a call to AsynContext.complete is made, this
method returns false."

Spring should do something else instead of relying on
isAsyncStarted(), something along these lines:

// Processing before calling startAsync()
request.setAttribute(SOME_SPRING_SPECIFIC_ATTRIBUTE, true);
AsyncContext context = request.startAsync();
// Pack the async context for later usage

// Later in the code
// if (asyncContext.isAsyncStarted()) WRONG CODE
if (asyncContext.getRequest().getAttribute(SOME_SPRING_SPECIFIC_ATTRIBUTE)
!= null)
    // Here you are sure that startAsync() has been called

Simone Bordet
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.

Back to the top