Skip to content

Clean Redis principal index during expiration cleanup - #3798

Closed
yeomin4242 wants to merge 2 commits into
spring-projects:4.0.xfrom
yeomin4242:gh-1715-redis-principal-index-cleanup
Closed

yeomin4242 wants to merge 2 commits into
spring-projects:4.0.xfrom
yeomin4242:gh-1715-redis-principal-index-cleanup

Conversation

@yeomin4242

Copy link
Copy Markdown

When Redis expiration events are unavailable, the expires key may be gone while the session hash remains available in the grace period. Clean the principal index during the existing expiration cleanup flow when that session is already expired.

Summary

  • clean stale Redis principal index entries from the existing Redis expiration cleanup flow
  • handle the case where sessions:expires:<sessionId> is already gone while the session hash is still available and expired
  • add a Redis static master/replica integration test that reproduces missing expiration events with RedisStaticMasterReplicaConfiguration

Addresses gh-1715.

Notes

This keeps the cleanup in RedisIndexedSessionRepository's expiration cleanup path. It does not change findByIndexNameAndIndexValue, so index lookups do not gain cleanup side effects.

The cleanup only removes the principal index entry when the session hash can still be loaded and the session is already expired. If the session hash is no longer available, this change leaves the index entry untouched.

This PR does not change SortedSetRedisSessionExpirationStore behavior.

When Redis expiration events are unavailable, the expires key
may be gone while the session hash remains available in the grace
period. Clean the principal index during the existing expiration
cleanup flow when that session is already expired.

Closes spring-projectsgh-1715

Signed-off-by: YeongJae Min <whereismysejong@naver.com>
@jzheaux
jzheaux force-pushed the gh-1715-redis-principal-index-cleanup branch from f0d4012 to 14ee599 Compare September 4, 2026 17:34
@jzheaux
jzheaux changed the base branch from main to 4.0.x September 4, 2026 17:40
@jzheaux jzheaux added type: bug A general bug in: redis labels Sep 4, 2026
@jzheaux jzheaux added this to the 4.0.6 milestone Sep 4, 2026
Signed-off-by: Josh Cummings <3627351+jzheaux@users.noreply.github.com>
@jzheaux jzheaux removed the status: waiting-for-triage An issue we've not yet triaged label Sep 4, 2026
@jzheaux

jzheaux commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Hi, @yeomin4242, thanks for the PR. I'm not yet convinced that what's needed is for expiration store to manually intervene. I've posted a theory and some code to #1715 and we'll see what comes of it. For now, I'm blocking this PR so it doesn't accidentally get merged while that investigation continues.

@jzheaux jzheaux added the status: blocked An issue that's blocked on an external project change label Sep 10, 2026
@yeomin4242 yeomin4242 closed this Sep 12, 2026
@yeomin4242
yeomin4242 deleted the gh-1715-redis-principal-index-cleanup branch September 12, 2026 08:51
@yeomin4242

Copy link
Copy Markdown
Author

Thanks for investigating this.

I tested the two-connection-factory configuration described in #1715 locally: RedisStaticMasterReplicaConfiguration with REPLICA_PREFERRED for RedisIndexedSessionRepository operations, and a RedisStandaloneConfiguration pointing to the master for RedisMessageListenerContainer. I also enabled Ex keyspace notifications and registered the standard Spring Session subscriptions.

With this setup, TTL expiration removed the PRINCIPAL_NAME_INDEX_NAME membership through the existing message-listener path. The test does not invoke cleanUpExpiredSessions(), so the expiration-store fallback proposed in this PR is not involved.

This suggests that separating the Pub/Sub connection addresses the stale-index scenario I reproduced. I agree that having the expiration store perform this cleanup is likely not the right direction.

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

Labels

in: redis status: blocked An issue that's blocked on an external project change type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants