spring-projects / spring-projects/spring-session

maxInactiveInterval < 0 but redis session still expired

Open
#3,362 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: bug
Dominant language
Java
Stars
1.9k
Forks
1.2k
Avg merge
4h 27m
Merged PRs (30d)
55

Description

Source:

https://github.com/spring-projects/spring-session/blob/2353d8b3cec4f0ed104c45f10d01acf278fe1dad/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java#L930-L962

Bug

The following code will always execute, Regardless of whether maxInactiveInterval is less than 0

RedisIndexedSessionRepository.this.sessionRedisOperations.boundHashOps(getSessionKey(getId()))
				.expire(fiveMinutesAfterExpires, TimeUnit.SECONDS);

This code in createShadowKey will always be skipped:

if (sessionExpireInSeconds < 0) {
	...
	RedisIndexedSessionRepository.this.sessionRedisOperations.boundHashOps(getSessionKey(getId()))
		.persist();
}

How to fix

long sessionExpireInSeconds = getMaxInactiveInterval().getSeconds();

createShadowKey(sessionExpireInSeconds);

if (sessionExpireInSeconds > 0) {
    long fiveMinutesAfterExpires = sessionExpireInSeconds + TimeUnit.MINUTES.toSeconds(5);
    RedisIndexedSessionRepository.this.sessionRedisOperations.boundHashOps(getSessionKey(getId()))
	.expire(fiveMinutesAfterExpires, TimeUnit.SECONDS);
}

RedisIndexedSessionRepository.this.expirationStore.save(this);
this.delta = new HashMap<>(this.delta.size());

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java around lines 930-962, then follow createShadowKey and the maxInactiveInterval entry point. Verify that negative intervals persist the session while positive intervals still apply the five-minute expiration, and confirm the expiration store is saved in both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis, spring
Domain
backend, databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.