Skip to content

Conversation

ddworken
Copy link
Contributor

@ddworken ddworken commented Sep 4, 2025

Summary

  • Added automatic cleanup of idle sessions when session count exceeds threshold
  • Sessions inactive longer than idle timeout are terminated to free resources
  • Prevents memory exhaustion from clients that create sessions but never terminate them

Changes

  • Added configurable session idle timeout (default 30 minutes)
  • Added background cleanup task that activates when session count > 10k
  • Track last activity time for each session
  • Double-check idle status before cleanup to prevent race conditions

Testing

  • Added tests for idle session cleanup behavior
  • Added tests for threshold-based activation
  • Added tests for session activity tracking
  • All existing tests continue to pass

This ensures the server remains stable even when clients don't properly close their sessions.

Implement automatic cleanup of idle sessions when session count exceeds
configurable threshold (default 10k). Sessions inactive for longer than
the idle timeout (default 30 minutes) are terminated to free resources.

This prevents memory exhaustion from clients that create sessions but
never send termination requests.
- Replace untyped lambdas with properly typed async functions
- Fix pyright reportUnknownLambdaType errors
- Apply ruff formatting
@ddworken ddworken marked this pull request as ready for review September 4, 2025 23:35
@ddworken ddworken requested a review from a team as a code owner September 4, 2025 23:35
@ddworken ddworken requested a review from ochafik September 4, 2025 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants