-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
commitSession() called twice #198
Comments
it is necessary to persist the session as soon as the response is committed to ensure the session is available to the clients as soon as the client has access to the session id. Consider the following scenario:
It is necessary to write after the session is committed because further modifications to the session might be made. For example:
It is generally recommended for a SessionRepository implementation to keep track of changes to ensure that only deltas are saved. You can see that this is how the Redis implementation provided with Spring Session behaves. Does this make sense now? |
Got it. Thanks |
It might be a good idea to add this into documentation. Thanks for detailed information. |
This commit optimizes SessionRepositoryFilter to avoid multiple retrievals of session from SessionRepository. Closes gh-1048
When Spring's session-scoped beans are used, it is actually committed only in the second time (in the finally block). This can be very confusing to the users. Also from the performance viewpoint, it is bad. But Spring session scoped beans are always set using Is there any configuration or settings that would store all the changes in one round. |
Not sure what you meant there @zeronone. From what I'm seeing in a request involving session scoped bean
For reasons explained in this comment, it wouldn't be safe to allow that. If you're dealing with a concrete problem, it's preferred to open a new issue and provide as much info as possible (ideally, coupled with a sample app) rather then to comment on a closed issue. |
@vpavic Here is the sequence of operations happening in our application.
The problem is that the session scoped beans are inserted back into the session ( |
@rwinch In our project, we are using redis as the storage, there is one master and two replica.
I have tried adding a conditional break point at the line before if condition, and let it pause a little while when key does not exist. And it turns out no problem(key exists, no exception). I have also tried that remove all my replica of redis, and there is no problem at all. |
Hi,
I'm developing custom SessionRepository.
I noticed that SessionRepositoryRequestWrapper.commitSession() called twice
This causes two calls of sessionRepository.save(session) and leads to persisting session to external storage twice.
What's the reason to commitSession() twice?
The text was updated successfully, but these errors were encountered: