Skip to content

RedisIndexedSessionRepository should remove original session id from expirations on changeSessionId - #4150

Open
dodoshell wants to merge 1 commit into
spring-projects:3.5.xfrom
dodoshell:gh-4149
Open

dodoshell wants to merge 1 commit into
spring-projects:3.5.xfrom
dodoshell:gh-4149

Conversation

@dodoshell

Copy link
Copy Markdown

Summary

When RedisIndexedSessionRepository saves a session after changeSessionId(), saveChangeSessionId() renames the session key first and only then calls expirationStore.remove(originalSessionId). MinuteBasedRedisSessionExpirationStore.remove() looks the session up by its id to compute the expiration bucket, so after the rename the lookup returns null and expires:<originalId> is left in spring:session:expirations:<minute>.

This change calls expirationStore.remove(this.originalSessionId) before the keys are renamed, as suggested in the issue.

Test plan

  • ./gradlew :spring-session-data-redis:test --tests org.springframework.session.data.redis.RedisIndexedSessionRepositoryTests (RED before fix: WantedButNotInvoked on boundSetOps(...).remove("expires:session-id"); GREEN after)
  • ./gradlew :spring-session-data-redis:check -x integrationTest (unit tests, checkstyle, format)

Closes #4149

MinuteBasedRedisSessionExpirationStore#remove looks the session up by
id to find its expiration set. saveChangeSessionId called it after the
session key had been renamed, so the lookup returned null and the
original id stayed in the expirations set. Remove it before renaming.

Closes spring-projectsgh-4149

Signed-off-by: dodoshell <326978213+dodoshell@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 2, 2026
@jhonatanhulse

Copy link
Copy Markdown

@dodoshell thank you for creating the PR.

I've noticed that the destination of your PR is the 3.5.x branch, but if I'm not wrong the bug was introduced in the 3.4.x version (#3122).

I believe merging the fix to the 3.4.x branch is more appropriate according to https://github.com/spring-projects/spring-session?tab=contributing-ov-file#create-your-branch-from-the-oldest-maintenance-branch.

I was also working on the same fix but since you created the PR first lets keep your changes.

The only difference between my changes and yours are the tests.

Feel free to use anything from my changes if necessary jhonatanhulse@f3d790c

Thank you very much.

@dodoshell

Copy link
Copy Markdown
Author

Thanks for taking a look, and for the link to your commit.

I based it on 3.5.x because 3.5.8 is the oldest open milestone and 3.4.x has none, so I took 3.5.x as the oldest maintenance branch still getting releases. If the maintainers would rather have it on 3.4.x, I'll retarget it; the change should apply there as is.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants