Skip to content

REF-8: Fix seconds/milliseconds mixup in in-memory session cleanup (issue #76)#87

Open
thomasnymand wants to merge 1 commit into
masterfrom
feature/REF-8-session-cleanup-seconds-millis
Open

REF-8: Fix seconds/milliseconds mixup in in-memory session cleanup (issue #76)#87
thomasnymand wants to merge 1 commit into
masterfrom
feature/REF-8-session-cleanup-seconds-millis

Conversation

@thomasnymand

Copy link
Copy Markdown
Collaborator

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 the DatabaseSessionHandler and the caller, which reads HttpSession.getMaxInactiveInterval(), both treat it). But InMemorySessionHandler.cleanup() passed that seconds value straight to TimeOutWrapper.isExpired(delay), which compares against System.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).
  • Correct the misleading "Milliseconds" javadoc on the cleanup contract (SessionHandler) and both implementations — the parameter is seconds.

Test

Adds an InMemorySessionHandlerTest regression 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 6485c2b and bc7b004), and adds the regression test those commits lacked.

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mixup of seconds and milliseconds in cleanup job for in memory session handler

1 participant