Skip to content

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

Merged
thomasnymand merged 1 commit into
masterfrom
feature/REF-8-session-cleanup-seconds-millis
Jul 6, 2026
Merged

REF-8: Fix seconds/milliseconds mixup in in-memory session cleanup (issue #76)#87
thomasnymand merged 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>
@thomasnymand
thomasnymand requested a review from mthiim July 2, 2026 07:37

@mthiim mthiim left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added one comment

* @param maxInactiveIntervalSeconds Seconds to store session, before it should be invalidated.
*/
@Override
public void cleanup(long maxInactiveIntervalSeconds) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@thomasnymand thomasnymand Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are perfectly right :) I suggest handling by adding clear and obvious documentation in release note.

@thomasnymand
thomasnymand merged commit 34cc35a into master Jul 6, 2026
2 checks passed
@thomasnymand
thomasnymand deleted the feature/REF-8-session-cleanup-seconds-millis branch July 6, 2026 12:11
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

2 participants