-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[master] Avoid extraneous call to SessionRespository.findById(...) in SessionRepositoryRequestWrapper.commitSession() #1732
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
Conversation
@pferraro Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@pferraro Thank you for signing the Contributor License Agreement! |
b8c56f6
to
92cb240
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @pferraro!
Could you add Closes gh-1731
to the commit message so that it will automatically close the issue you created?
@eleftherias Done. |
The lookup might seem redundant when one considers only what happens within the scope of this method (or even JVM), but have in mind that one of the core challenges Spring Session solves is session management in a cluster. With that in mind, this needs to be looked at having in mind the scenarios with concurrent requests. The session id validity check that guards the invocation of An important bit of context here is that So the change proposed here IMO shouldn't be done without considering a more substantial review of the whole arrangement. |
Concurrent requests to a given Session by multiple cluster members are forbidden by section 7.7.2 of the Servlet specification:
Thus, we only need to be concerned with concurrent requests for a given Session within a single JVM.
Assuming that the state referenced by a Session returned by SessionRepository.findById(...) for a given request is, by definition, up-to-date until the corresponding Session#save completes, can we not simply reorder this logic such that we perform the session id validity check before Session#save?
It seems to me that a SessionRepository implementation that persists an invalid session is incorrect, no? |
…epositoryRequestWrapper.commitSession() due to premature cache clearing. Closes spring-projectsgh-1731
I'm afraid the excerpt you're quoting isn't really applicable to modern environments, as nowadays we typically have a round robin based load-balancers that distribute requests evenly between the nodes in a cluster. Spring Session is exactly here to address that scenario so that users don't have to resort to anti-patterns like sticky sessions (which is something Servlet spec seems to suggest there).
Logically, the concern I'm expressing here would still be present, because
Yes, I agree with you there and that's exactly why I opened #1277. |
Can you describe a scenario where the proposed change is problematic - that is not already problematic using the current logic? |
Any update on this? |
Closing in favor of gh-1909 |
Resolves #1731
Clearing the requested session cache after we've written the session ID to the response avoid the need for a redundant lookup of the session.