Affects: Tested with 4.2.4/4.2.9/4.3.6
I'm using spring DeferredResult on a http request. The controller receives some info, make a query or two and then return the DeferredResult.
final RandomObj randomObj = someDAO.getSomething(someParameters);
final CustomResponse response = new CustomResponse();
response.setError("need_password");
return new DeferredResult<CustomResponse>(10L, response);
But for some reason Hibernate Session is not being closed after the return of after the timeout expires.
In c3p0 there is the option to kill long unreturned connections and debug the problem, and with the DeferredResult scenario I always get this after a while:
jul 16, 2019 10:42:26 AM com.mchange.v2.resourcepool.BasicResourcePool removeResource
INFO: A checked-out resource is overdue, and will be destroyed: com.mchange.v2.c3p0.impl.NewPooledConnection@13b130de
jul 16, 2019 10:42:26 AM com.mchange.v2.resourcepool.BasicResourcePool removeResource
INFO: Logging the stack trace by which the overdue resource was checked-out.
java.lang.Exception: DEBUG STACK TRACE: Overdue resource check-out stack trace.
I confirmed that the session is not closed by putting some breakpoints on the Session.close() method.
I think my problem is the following: Here 3 interceptors are registered, the AsyncRequestInterceptor is the second one. When the timeout trigger,this code is executed, it first trigger this interceptor, after that, since there is a timeout result, it is assigned as the result. When the iteration is over and the second interceptor (AsyncRequestInterceptor) would be run, the result of setOrExpired (because the timeout result) is true, and it break the execution of the interceptor loop. Because of that the AsyncRequestInterceptor don't get flagged here, and it does not close the hibernate session
If I don't put a timeout result object it works as expected, closing the session.
That is the expected behavior??
Comment From: rstoyanchev
@brunomanzo it is not very clear what the 3 interceptors are, which one sets the timeout value, and what that value is. Whatever the value, that will trigger an async dispatch to complete handling, and during that dispatch the AsyncInterceptor
should be allowed to complete and cleanup.
Note that the 4.2.x branch is not supported and we cannot answer questions relative to that. You need to be on the latest 4.3.x release in order to ensure you have fixes for CVE reports.
Comment From: brunomanzo
@rstoyanchev Hello!! The application is kinda old, but no problem! I tested on 4.3.6 and sitll got problems! I was able to reproduce it: https://github.com/brunomanzo/deferredresulttest Could you take a look?
Just make a request to the controller and wait a while, this will be show on console:
jul 17, 2019 1:22:23 PM com.mchange.v2.resourcepool.BasicResourcePool removeResource
INFO: A checked-out resource is overdue, and will be destroyed: com.mchange.v2.c3p0.impl.NewPooledConnection@7337e015
jul 17, 2019 1:22:23 PM com.mchange.v2.resourcepool.BasicResourcePool removeResource
INFO: Logging the stack trace by which the overdue resource was checked-out.
java.lang.Exception: DEBUG STACK TRACE: Overdue resource check-out stack trace.
Comment From: brunomanzo
@rstoyanchev Hello, any news on this?
Comment From: snicoll
@brunomanzo sorry but I haven't managed to run your sample. I did setup postgres but then the context does not start. I unfortunately can't justify trying to fix it given this version of Spring is now EOL. If you can reproduce on a supported version, then please update the sample and we can take another look.