-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Using types in @SessionAttributes
is sometimes not reflected in the model
#30463
Comments
I am confused. If you want to share the session between different servers, you should be using Spring Session and make sure that its state is shared accordingly. With that said, can you share a small sample that shows the problem you've described, with proper replication of the session (Spring Session or otherwise). |
@snicoll Sorry for the poor explanation. This issue assumes that we are using Spring Session for session management and using an external for Session Store. (I am using Redis in my environment).
3 is particularly troublesome, making it difficult to notice problems in the production environment.
Correct. I'll try to make a sample. |
@snicoll I made a sample. |
@SessionAttributes
is sometimes not reflected in the Model
Thanks for the sample. I want to acknowledge I've seen the sample but haven't had the time to dig into it. Perhaps this rings a bell for you @rstoyanchev? |
@SessionAttributes
is sometimes not reflected in the Model
@SessionAttributes
is sometimes not reflected in the model
I've implemented this through storing a copy of the known attribute names in the actual session on |
Thank you for everyone's support. |
@SessionAttributes stores the session object specified by the following attributes in the Model for each method of the annotated Controller.
The process is implemented in SessionAttributesHandler#retrieveAttributes(WebRequest), but sometimes it is not reflected in the Model because it only looks at
knownAttributeNames
.The object specified in
types
is not initially defined inknownAttributeNames
, but is added toknownAttributeNames
when DI by a controller method.Instances of
SessionAttributesHandler
are cached, so information added toknownAttributeNames
is preserved, but it is only valid within the same VM since it is not stored in the session.Therefore, if different methods of the same Controller are executed on different servers, the expected behavior will not occur because the
knownAttributeNames
state will be different.e.g.) If handle1 and handle2 below are executed on different servers, Pet is not stored in handle2's model.
Defining the above in
names
instead oftypes
will result in the expected behavior on different servers.I do not think this behavior is what is expected.
Note that this problem does not occur when
SessionAttributesHandler
is the same on all servers.The problem is easily missed because it occurs immediately after a server restart when the
SessionAttributesHandler
cache is different.The text was updated successfully, but these errors were encountered: