spring-projects / spring-projects/spring-session
maxInactiveInterval < 0 but redis session still expired
Open
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:
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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