Skip to content

Conversation

@CodeWithKyrian
Copy link
Contributor

Problem

The CacheSessionHandler could get into an inconsistent state where sessions exist in the cache but are missing from the session index, or vice versa. This happens due to:

  • Partial write failures between index and session data
  • Race conditions during garbage collection
  • Cache backend inconsistencies or network issues

Solution

Added self-healing logic to the read() method that:

  • Auto-repairs missing index entries: When a session exists in cache but not in index, automatically add it to the index
  • Cleans up stale index entries: When index references a non-existent session, remove it from the index
  • Maintains existing behavior: TTL checks and expiration logic remain unchanged

Changes

  • Enhanced CacheSessionHandler::read() with consistency checks and auto-repair
  • No breaking changes to the public API
  • Backward compatible with existing session data

Testing

This fix is defensive and maintains all existing behavior while preventing inconsistent states that could cause session lookup failures.

- Auto-repair when session exists in cache but missing from index
- Clean up index when session doesn't exist in cache
- Prevents inconsistent state between session data and index
@CodeWithKyrian CodeWithKyrian merged commit f33db1f into main Jun 27, 2025
8 checks passed
@CodeWithKyrian CodeWithKyrian deleted the fix/cache-session-handler-index-consistency branch June 27, 2025 08:39
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.

2 participants