Skip to content

fix: Prevent JavaScript heap out of memory crash#60

Open
thoraxe wants to merge 1 commit intovultuk:mainfrom
thoraxe:fix/memory-leak-cleanup
Open

fix: Prevent JavaScript heap out of memory crash#60
thoraxe wants to merge 1 commit intovultuk:mainfrom
thoraxe:fix/memory-leak-cleanup

Conversation

@thoraxe
Copy link

@thoraxe thoraxe commented Jan 20, 2026

Summary

  • Add automatic session cleanup (removes inactive sessions after 24h with no connections)
  • Add WebSocket heartbeat cleanup (terminates orphaned connections after 60s)
  • Add hourly auto-cleanup to UsageAnalytics with sessionHistory size limit (100 entries)
  • Add caching to expensive UsageReader methods (getCurrentSessionStats, detectOverlappingSessions)
  • Add memory monitoring in dev mode (logs heap usage every 5 minutes)
  • Remove unused historicalData array from UsageAnalytics

Test plan

  • Run server in dev mode and verify memory logging appears every 5 minutes
  • Create sessions, leave them inactive for 24+ hours, verify cleanup occurs
  • Disconnect client abruptly (kill browser), verify WebSocket cleanup after 60s
  • Monitor heap usage over extended runtime to verify memory stabilizes

🤖 Generated with Claude Code

Add automatic cleanup mechanisms to prevent unbounded memory growth:

- Session cleanup: Remove inactive sessions (24h+, no connections, no active agent) every 5 minutes
- WebSocket cleanup: Detect and terminate orphaned connections (no heartbeat for 60s) every 30 seconds
- UsageAnalytics: Add hourly auto-cleanup interval, limit sessionHistory to 100 entries, add destroy() method
- UsageReader: Add caching for expensive methods (getCurrentSessionStats 5s, detectOverlappingSessions 30s)
- Memory monitoring: Log heap usage every 5 minutes in dev mode

Also removes unused historicalData array from UsageAnalytics.

Co-Authored-By: Claude Opus 4.5 <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.

1 participant