On Wed, Jul 13, 2016 at 8:00 AM, Violeta Georgieva <miles...@gmail.com>
wrote:

> Hi,
>
> 2016-07-12 23:27 GMT+03:00 Rossen Stoyanchev <rstoyanc...@pivotal.io>:
> >
> > hi-
> >
> > Starting with Tomcat 8.0.35 when an async request times out, in a
> > subsequent error dispatch request.isAsyncStarted() returns true.
> Previously
> > it returned false.
> >
> > The Servlet spec says:
> > 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.
>
> I think the following part of the specification is important:
>
> "
> In the event that an asynchronous operation times out, the container must
> run through the following steps:
> - Invoke the AsyncListener.onTimeout method on all the AsyncListener
> instances registered with the ServletRequest on which the asynchronous
> operation was initiated.
> - If none of the listeners called AsyncContext.complete() or any of the
> AsyncContext.dispatch methods, perform an error dispatch with a status code
> equal to HttpServletResponse.SC_INTERNAL_SERVER_ERROR.
> - If no matching error page was found, or the error page did not call
> AsyncContext.complete() or any of the AsyncContext.dispatch methods, the
> container MUST call AsyncContext.complete().
> "
>
> So isAsyncStarted returns true when in the error page and the error page
> should call AsyncContext.complete.
>
> What do you think?
>


My understanding of the general idea with async requests is that after
startAsync(), isAsyncStarted remains true until the thread exits. In
subsequent dispatches of any kind, isAsyncStarted is false and the
application is free to call startAsync again and exit the thread. The fact
that isAsync now returns true in an ERROR dispatch seems to go against that
general idea.

For more background, the issue was reported with a Spring Boot application
that has an SSE endpoint. In Spring Boot error dispatches are used
extensively where the same URL routing mechanisms is applied as for regular
requests. Prior to invoking the handler we have simple a sanity check to
make sure asyncStarted is false. We could remove that check but then it
means an error handler no longer can call startAsync.

For what it's worth this very long standing behavior, from the beginning of
Servet 3.0, which runs and is used without issues against many 3.0
containers. This is why I wondered if this is an intentional change of
behavior that now makes Tomcat behave differently from other containers.

Reply via email to