REF-8: Fix seconds/milliseconds mixup in in-memory session cleanup (issue #76) - #87
Merged
Merged
Conversation
…ssue #76) InMemorySessionHandler.cleanup received the timeout in seconds (per the SessionHandler#cleanup contract and the DatabaseSessionHandler) but passed it straight to TimeOutWrapper.isExpired(), which compares against System.currentTimeMillis() and therefore expects milliseconds. As a result sessions on the in-memory handler expired 1000x too early - a 30 minute timeout became 1.8 seconds - logging users out on almost every cleanup run. The database session handler was unaffected. Convert seconds to milliseconds before the expiry comparison, and fix the SessionCleanerTask debug log that printed the timeout inconsistently. Correct the misleading "Milliseconds" javadoc on the cleanup contract (SessionHandler) and both implementations - the value is seconds. Add an InMemorySessionHandlerTest regression test asserting a stored assertion survives until its real (seconds) timeout. Ports the fix from the Trifork fork (Jeppe Sommer, commits 6485c2b and bc7b004) and adds the previously missing test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mthiim
approved these changes
Jul 3, 2026
mthiim
left a comment
Collaborator
There was a problem hiding this comment.
I have added one comment
| * @param maxInactiveIntervalSeconds Seconds to store session, before it should be invalidated. | ||
| */ | ||
| @Override | ||
| public void cleanup(long maxInactiveIntervalSeconds) { |
Collaborator
There was a problem hiding this comment.
My only concern is if someone previously called this method and is relying on the old behavior (maybe they found the error and compensated by passing in milliseconds, meaning now they will overshoot by 1000x). Probably not a big issue - either the current method could be kept as is and a new cleanup addded, but maybe better to just document it clearly when releasing?
Collaborator
Author
There was a problem hiding this comment.
You are perfectly right :) I suggest handling by adding clear and obvious documentation in release note.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #76
Summary
On the in-memory session handler, sessions expired ~1000x too early — a 30-minute timeout became 1.8 seconds — logging users out on almost every cleanup run. The database session handler was not affected.
Root cause:
SessionHandler.cleanup(long maxInactiveIntervalSeconds)takes the timeout in seconds (as theDatabaseSessionHandlerand the caller, which readsHttpSession.getMaxInactiveInterval(), both treat it). ButInMemorySessionHandler.cleanup()passed that seconds value straight toTimeOutWrapper.isExpired(delay), which compares againstSystem.currentTimeMillis()and therefore expects milliseconds.Fix
InMemorySessionHandler.cleanup()— convert seconds → milliseconds before the expiry comparison.SessionCleanerTask— fix the debug log that printed the timeout inconsistently (* 1000).cleanupcontract (SessionHandler) and both implementations — the parameter is seconds.Test
Adds an
InMemorySessionHandlerTestregression test that stores an assertion, waits well past the buggy milliseconds interpretation but far short of the real seconds timeout, and asserts the assertion is still present. Full suite:Tests run: 108, Failures: 0, Errors: 0.Attribution
Ports the fix from the Trifork fork (Jeppe Sommer, commits
6485c2bandbc7b004), and adds the regression test those commits lacked.🤖 Generated with Claude Code