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

Init mongo session with max inactive interval seconds #3130

Closed
wants to merge 1 commit into from

Conversation

dlscjf151
Copy link
Contributor

description

There is a bug when creating a session using the mongo session repository.
The mongo session repository only passes the session id generator or created session id to the constructor of mongo session when creating it. And the mongo session sets the initial expiration date to createdAt plus the default max inactive interval time of 30 minutes. So no matter what the developer sets the max inactive interval time to in the mongo session repository, it will always be 30 minutes on initial creation. I fixed this by passing the max inactive interval time along with the mongo session creation so that it is applied correctly.

code

MongoIndexedSessionRepository

MongoSession session = new MongoSession(this.sessionIdGenerator);
session.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
publishEvent(new SessionCreatedEvent(this, session));

MongoSession

MongoSession(String id, long maxInactiveIntervalInSeconds) {
  this.id = id;
  this.originalSessionId = id;
  this.intervalSeconds = maxInactiveIntervalInSeconds;
  setLastAccessedTime(Instant.ofEpochMilli(this.createdMillis));
}

MongoSession(SessionIdGenerator sessionIdGenerator) {
  this(sessionIdGenerator.generate(), MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
  this.sessionIdGenerator = sessionIdGenerator;
}

The issue code is modifying the default max inactive interval time after it was applied to the default of 30 minutes on initial creation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 10, 2024
@marcusdacoregio
Copy link
Contributor

Hi @dlscjf151, thanks for the PR.

Would you please add tests that assert the problem has been fixed?

@marcusdacoregio marcusdacoregio self-assigned this Aug 21, 2024
@marcusdacoregio marcusdacoregio added type: bug A general bug in: mongo-db and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 21, 2024
@marcusdacoregio
Copy link
Contributor

Thanks @dlscjf151, this has been fixed via d989024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants