Bug 54123

Summary: servlet 3.0 spec violation in async timeout processing
Product: Tomcat 7 Reporter: Eugene Chung (TmaxSoft) <bluewolf.chung>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: major    
Priority: P2    
Version: trunk   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: test war file within java source

Description Eugene Chung (TmaxSoft) 2012-11-09 10:30:48 UTC
Created attachment 29575 [details]
test war file within java source

Servlet 3.0 Spec. says that Asynchronous processing


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().

(servlet-3_0-mrel-spec.pdf / pdf page 40, Spec page 18)

In other words, if there are no AsyncListeners which calls AsyncContext.complete() or any of the 
AsyncContext.dispatch, the container must perform an error dispatch with 500 error code.

But tomcat 7 does not send 500 error response. It sends 200 OK.

In org.apache.catalina.core.AsyncContextImpl.timeout(), 

                if (listenerInvoked) {
                            ActionCode.ASYNC_IS_TIMINGOUT, result);
                    return !result.get();
                } else {
                    // No listeners, container calls complete

it just calls complete(). So I think it must be spec violation.

I've attached the test war file within a test source.
Test URL is http://localhost:8080/asyncTimeoutTest/AsyncTimeoutTestServlet .
Comment 1 Mark Thomas 2012-11-11 23:36:37 UTC
Fixed in trunk and 7.0.x and will be included in 7.0.33 onwards.

"error dispatch" is not defined anywhere I could find in the servlet spec. I implemented based on what I could deduce from the spec text quoted in this issue.
Comment 2 Eugene Chung (TmaxSoft) 2012-11-12 01:26:01 UTC
Yes, I haven't seen the def. of 'error dispatch', too. In our product, I just used response.sendError(500) that was internally using forward with DispatcherType.ERROR.