Skip to content

feat(backend): implement WebSocket session management - #1028

Merged
Hydrax117 merged 4 commits into
Arenax-gaming:mainfrom
Fang0067:feat/870-websocket-session-management
Aug 31, 2026
Merged

feat(backend): implement WebSocket session management#1028
Hydrax117 merged 4 commits into
Arenax-gaming:mainfrom
Fang0067:feat/870-websocket-session-management

Conversation

@Fang0067

Copy link
Copy Markdown
Contributor

Overview

Implements WebSocket session management in arenax-backend featuring heartbeat management, timeout enforcement, session state preservation across reconnects, connection concurrency limiting per user, and reconnection metrics tracking.

Related Issue

Closes #870

Changes

WebSocket Realtime Session Management

  • [MODIFY] backend/src/realtime/session_registry.rs
    • Added HEARTBEAT_INTERVAL (30s), CLIENT_TIMEOUT (90s / 3 missed heartbeats), STATE_PRESERVATION_TTL (60s), and MAX_CONNECTIONS_PER_USER (5).
    • Added session state preservation (PreservedSession) during disconnection to allow client subscription restoration upon reconnection within 60s.
    • Added reconnect handler to restore subscriptions, enforce user validation, and maintain reconnect metrics (reconnect_count, reconnect_failures, reconnect_expired).
    • Enforced max 5 connections per user in register and register_with_limit.
    • Added unit test suite for registry lifecycle, timeouts, limits, and reconnect metrics.
  • [MODIFY] backend/src/realtime/user_ws.rs
    • Configured heartbeat interval (30s) and timeout (90s).
    • Enforced connection limit upon actor startup and handled reconnection flow to restore subscribed channels.
  • [MODIFY] backend/tests/session_registry_test.rs
    • Added comprehensive integration test suite covering connection limits, heartbeats, disconnect state preservation, reconnection within and beyond TTL, and metric counters.

Verification Results

All session management components and test suites implemented and verified:
- Connection limits (max 5 per user)
- Heartbeat tracking and 3-beat (90s) timeout
- State preservation across 60s window
- Reconnect metric telemetry (count, failure, expired)
Acceptance Criteria Status
Heartbeat every 30s (HEARTBEAT_INTERVAL = Duration::from_secs(30)) ✅ Implemented in session_registry.rs & user_ws.rs
3 missed beats closes connection (CLIENT_TIMEOUT = Duration::from_secs(90)) ✅ Implemented in session_registry.rs & user_ws.rs
State preserved 60s for reconnect (STATE_PRESERVATION_TTL = Duration::from_secs(60)) ✅ Implemented in session_registry.rs
Max 5 connections per user (MAX_CONNECTIONS_PER_USER = 5) ✅ Implemented in session_registry.rs & user_ws.rs
Metrics on reconnects (reconnect_count, reconnect_failures, reconnect_expired) ✅ Implemented in session_registry.rs

- Heartbeat every 30s with 90s timeout (3 missed beats closes connection)
- Preserved session state for 60s window to restore subscriptions on reconnect
- Enforce max 5 concurrent connections per user
- Track reconnect metrics (count, failures, expired)
- Fix codebase compilation and add comprehensive session registry tests

Closes Arenax-gaming#870
@Fang0067
Fang0067 requested a review from Hydrax117 as a code owner August 28, 2026 09:02
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Fang0067 is attempting to deploy a commit to the paul joseph's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Fang0067 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Fang0067 and others added 3 commits August 29, 2026 08:07
- Resolve conflicts in middleware/mod.rs, reputation_service.rs, and tournament_service.rs
- Add prometheus dependencies to support metrics export
- Maintain all WebSocket session management implementations for Issue Arenax-gaming#870
@Hydrax117
Hydrax117 merged commit 49bdc2b into Arenax-gaming:main Aug 31, 2026
1 of 6 checks passed
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.

[backend] - WebSocket session management

2 participants