Skip to content

feat: add a "connection_disrupted" mode while server wait for client reconnect#2789

Merged
idoros merged 7 commits intomainfrom
ido/handle-reconnect-2
Nov 16, 2025
Merged

feat: add a "connection_disrupted" mode while server wait for client reconnect#2789
idoros merged 7 commits intomainfrom
ido/handle-reconnect-2

Conversation

@idoros
Copy link
Contributor

@idoros idoros commented Nov 16, 2025

This PR introduces a graceful reconnection mechanism for WebSockets, improving resilience during transient disconnects.

Key Changes

  1. New message type: connection_disrupted
    Emitted immediately when a client disconnects before the server begins the disposal grace period.
  2. Delayed client disposal
    Instead of disposing clients immediately on disconnect, the server now waits for a configurable grace period (disposeGraceMs, default: 2 minutes).
    During this period the server tracks a queue of messages that would have been sent to the client.
  3. Reconnection handling
    When a client reconnects:
    • If reconnection occurs before the grace period expires:
      • Client environments are called with 'ready' messages to transition them out of pending.
      • A 'server-connection-restored' message is sent to notify the client.
    • If reconnection occurs after the grace period expires:
      • A 'server-lost-client-state' message is sent, signaling that the client must refresh state.

Additionally the timout and reconnection setting on the server socket has been set to lower defaults to all fast reconnect.

idoros and others added 3 commits November 16, 2025 08:18
…t and during the server re-connect grace time

- wsClientHost sends a "server-lost-client-state" or "server-connection-restored" to a reconnecting client to inform it of its server state
- set shorter default reconnect times to ws client
- add a close method the WsClientHost
@idoros idoros requested a review from barak007 November 16, 2025 06:56
@idoros idoros merged commit 9c83a9e into main Nov 16, 2025
6 checks passed
@idoros idoros deleted the ido/handle-reconnect-2 branch November 16, 2025 13:48
AviVahl added a commit that referenced this pull request Nov 18, 2025
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