Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how HandlerInterceptor can hook into async request timedout [SPR-12720] #17317

spring-issuemaster opened this issue Feb 16, 2015 · 3 comments


None yet
2 participants
Copy link

commented Feb 16, 2015

Stepan Koltsov opened SPR-12720 and commented

When async request is timed out, neither HandlerInterceptor.postHandle nor HandlerInterceptor.afterCompletion is called.

How to reproduce a problem.

  1. Clone github project:

interesting file is:

as you see, InterceptorDemo prints to stdout information about all interceptor events.

  1. Start demo from InterceptorDemo class

  2. Open


in browser. Wait for 61 second.

Stdout would be like this:

preHandle /async
afterConcurrentHandlingStarted /async
2015-02-16 20:56:00.829 ERROR 8128 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost]           : Exception Processing ErrorPage[errorCode=0, location=/error]
java.lang.IllegalStateException: Cannot forward after response has been committed
... (stack trace skipped)

As you may see, postHandle and afterCompletion interceptors are not called.

I don't know any workaround for this problem.

I used latest available spring-boot and its default dependencies, which are:

spring-boot 1.2.1.RELEASE
spring 4.1.4.RELEASE
tomcat 8.0.15

Affects: 4.1.4

Issue Links:

  • #17209 Document how HandlerInterceptor should differentiate an ASYNC dispatch

Referenced from: commits 1803978


This comment has been minimized.

Copy link
Collaborator Author

commented Feb 16, 2015

Rossen Stoyanchev commented

This is actually expected behavior since there is no Servlet container dispatch when a timeout occurs. In the Servlet 3.0 API a timeout event is exposed as an javax.servlet.AsyncListener callback.

So instead a HandlerInterceptor can choose to register to be involved in the timeout from its preHandle method. You can see for example what the OpenSessionInViewFilter and OpenSessionInViewInterceptor do to ensure the Hibernate session is released in case of timeout by registering AsyncRequestInterceptor.


This comment has been minimized.

Copy link
Collaborator Author

commented Feb 16, 2015

Stepan Koltsov commented

Thanks for the explanation.


This comment has been minimized.

Copy link
Collaborator Author

commented Feb 18, 2015

Rossen Stoyanchev commented

Turning into documentation task right along with related ticket #17209.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.