Bug 57252

Summary: Custom error page is not used for an error that occurs asynchronously
Product: Tomcat 7 Reporter: Andy Wilkinson <andy.wilkinson>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 7.0.57   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Small app to reproduce the problem

Description Andy Wilkinson 2014-11-24 15:00:26 UTC
Created attachment 32224 [details]
Small app to reproduce the problem

If an error is sent as part of some asynchronous processing, for example:

@WebServlet(value = "/async", asyncSupported=true)
public class AsyncServlet extends HttpServlet {
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		final AsyncContext context = request.startAsync();
		context.start(new Runnable() {
			@Override
			public void run() {
				try {
					response.sendError(500);
				} catch (IOException e) {
				}
				context.complete();
			}
		});
	}
}

Tomcat 7.0.57 renders its default error page rather than the configured custom error page. The same behaviour is also exhibited in recent 8.0.x releases. It's perhaps worth noting that Tomcat 7.0.55 renders an entirely blank page in this scenario.

My expectation is that the custom error page is used and, FWIW, this is what Jetty does.

I have attached a war that can be used to reproduce the problem. /sync can be used to confirm that the custom error page is working. /async will reproduce the problem described above.
Comment 1 Mark Thomas 2014-12-02 15:07:42 UTC
FYI. I am currently working on this but my test cases have identified a further concurrency issue with the error handling that I am going to have to fix first.
Comment 2 Mark Thomas 2014-12-04 13:35:05 UTC
Proposed fix:
https://github.com/markt-asf/tomcat/commit/5e195b2f06dba1be3f90b0a9d1f67604af905e47

I'll commit this once the svn server returns to read/write
Comment 3 Mark Thomas 2014-12-05 11:46:16 UTC
Test case created and fix applied to trunk, 8.0.x (for 8.0.16) and 7.0.x for (7.0.58).