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

Closed
spring-projects-issues opened this issue Feb 16, 2015 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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:

https://github.com/stepancheg/spring-webmvc-async-interceptor

interesting file is:

https://github.com/stepancheg/spring-webmvc-async-interceptor/blob/master/src/main/java/demo/InterceptorDemo.java

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

  1. Start demo from InterceptorDemo class

  2. Open

http://localhost:8080/async?s=61000

in browser. Wait for 61 second.

Stdout would be like this:

preHandle /async
afterConcurrentHandlingStarted /async
DeferredResult.onTimeout
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)
returning

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:

Referenced from: commits 1803978

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

Stepan Koltsov commented

Thanks for the explanation.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues 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
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants