Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
CachingConnectionFactory - Invalid session in session cache [SPR-16450] #20995
I have a suspicion there is a small possibility, that invalid session (session, which belongs to the "old" connection) is returned into session cache (
Two threads - T1 and T2. T1 asks for connection and session and then close the acquired session (session is put into the session cache).
Now, the thread T2 invokes
I know that invocation of
Now, the session, which was acquired by T1 in a moment when
I attached "demonstration" test, which shows this behavior. Unfortunately I am unable to write this test, without modification of
Content of "demonstration" zip package:
I know that there is very small chance to reach this scenario (small time range, all close operations must be success ...), but anyway, I still feel "synchrozation" problem here. In addition my fix proposal is too "invasive" (signature of protected methods was changed ...). Maybe there is a better way how to fix this problem:
The main motivation for creating this issue was, that we have strange problems in old Spring (3.0.x), which can be caused by this problem. Maybe/probably the situation should be better from a moment when #16762 was done. But I think, that "synchronization" problem still exists.
Backported to: 4.3.15
Juergen Hoeller commented
The simplest solution here could be to move the
I'm about to commit this to master. Would be great if you could give it a try once available!
Radek Kraus commented
It sounds good for me. I think, that short term fallback to a physical session for intermediate calls is OK.
I modified my test case and it seems it works as expected - using physical session instead of cached session for intermediate calls (even in case, when session can be saved into session cache, because it was already created from "current" valid connection, but