Skip to content
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

[SessionRepositoryFilter] double save session to repository #2218

Closed
edgar-dev20 opened this issue Dec 6, 2022 · 9 comments
Closed

[SessionRepositoryFilter] double save session to repository #2218

edgar-dev20 opened this issue Dec 6, 2022 · 9 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@edgar-dev20
Copy link

Expected Behavior

When we use sessionRepositryFilter we find the session once and save it to the repository once at the end of the request

Current Behavior
SessionRepositryFilter at the end of the request find the session 2 times and save it twice. It's all about

Why is this necessary if after all the filters we still make a commit?

Maybe just use the final commit?

@edgar-dev20 edgar-dev20 added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Dec 6, 2022
@buzzerrookie
Copy link

As far as I know, the first commitSession is necessary, as it is intended for committed response. When a response is committed, the first commitSession is called, and the cookie header and other headers are written to the response. Because the response headers can not be modified once a response is commited, we need to do these before the response is committed.

@edgar-dev20
Copy link
Author

edgar-dev20 commented Jan 19, 2023

As far as I know, the first commitSession is necessary, as it is intended for committed response. When a response is committed, the first commitSession is called, and the cookie header and other headers are written to the response. Because the response headers can not be modified once a response is commited, we need to do these before the response is committed.

how are headers and cookies related to the session object in storage?

@buzzerrookie
Copy link

In commitSession method of class SessionRepositoryRequestWrapper, HttpSessionIdResolver is used to set session id via cookie or header. This happens before the response is committed.

@ravenadesk
Copy link

ravenadesk commented Jul 8, 2023

@buzzerrookie
I am not sure if it is a bug, but I am facing the inconsistency between the two saves when using redis with replica.

In our project, we are using redis as the storage, there is one master and two replica.
When I was testing /health endpoint with a little load, sometimes the second save cannot get the right session status (taking it as not stored in redis) throwing IllegalStateException

@Override
public void save(RedisSession session) {
	if (!session.isNew) {
		String key = getSessionKey(session.hasChangedSessionId() ? session.originalSessionId : session.getId());
		Boolean sessionExists = this.sessionRedisOperations.hasKey(key);
		if (sessionExists == null || !sessionExists) {
			throw new IllegalStateException("Session was invalidated");
		}
	}
	session.save();
}

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.
So I am wondering is this twice save patten conflict against replica synchronization of redis.

@marcusdacoregio
Copy link
Contributor

Hi, @ravenadesk. I think your issue might be related to #2021

@ravenadesk
Copy link

@marcusdacoregio
Thank you.
But my problem is that there exists the possibility to not able to get session from replica after just set it.
I have adjusted my config to not use read replica.

@marcusdacoregio
Copy link
Contributor

Hi, @edgar-dev20. Can you provide an example where this might be causing problems for you? We have to make sure that we commit the session when response is committed because after that we might see errors like Cannot create a session after the response has been committed.

@marcusdacoregio marcusdacoregio self-assigned this Dec 27, 2023
@marcusdacoregio marcusdacoregio added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 27, 2023
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Jan 3, 2024
@spring-projects-issues
Copy link

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2024
@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants