Skip to content

maxInactiveInterval < 0 but redis session still expired #3362

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

Open
hdsuperman opened this issue Mar 25, 2025 · 0 comments
Open

maxInactiveInterval < 0 but redis session still expired #3362

hdsuperman opened this issue Mar 25, 2025 · 0 comments
Labels
status: waiting-for-triage An issue we've not yet triaged type: bug A general bug

Comments

@hdsuperman
Copy link

Source:

createShadowKey(sessionExpireInSeconds);
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());
}
private void createShadowKey(long sessionExpireInSeconds) {
String keyToExpire = "expires:" + getId();
String sessionKey = getSessionKey(keyToExpire);
if (sessionExpireInSeconds < 0) {
BoundValueOperations<String, Object> valueOps = RedisIndexedSessionRepository.this.sessionRedisOperations
.boundValueOps(sessionKey);
valueOps.append("");
valueOps.persist();
RedisIndexedSessionRepository.this.sessionRedisOperations.boundHashOps(getSessionKey(getId()))
.persist();
}
if (sessionExpireInSeconds == 0) {
RedisIndexedSessionRepository.this.sessionRedisOperations.delete(sessionKey);
}
else {
BoundValueOperations<String, Object> valueOps = RedisIndexedSessionRepository.this.sessionRedisOperations
.boundValueOps(sessionKey);
valueOps.append("");
valueOps.expire(sessionExpireInSeconds, TimeUnit.SECONDS);
}
}

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());
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 type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant