Skip to content

WebSocket heartbeat: send pings, detect dead connections, cap auth retries #186

Description

@gnacho

The official push client keeps the notify_push WebSocket healthy with an active heartbeat and bounds authentication retries. src/libsync/pushnotifications.cpp:

  • PING_INTERVAL = 30s: sends a WS ping (pingWebSocketServer), arms a 30s _pingTimedOutTimer; if no pong arrives in time (onPingTimedOut) it tears down and reconnects (setup()).
  • MAX_ALLOWED_FAILED_AUTHENTICATION_ATTEMPTS = 3: after 3 failed auth attempts tryReconnectToWebSocket returns false and stops retrying.
  • _reconnectTimerInterval = 20s for reconnect attempts.

Current state in nextsync-rs: push.rs handles inbound Message::Ping (responds with pong, line 621-625) but never sends its own ping and has no pong-timeout detection, so a half-dead TCP connection (like the stuck dhclient that took down hub.cloudless.club on 26-Aug) can sit silently with no notifications flowing and no reconnect. Auth retries exist (AuthRequired -> state + reconnect via BACKOFF_SECONDS [2,5,10,30,60,300]) but there is no cap on total failed attempts, so an invalid credential could retry forever.

Proposed work:

  1. Send a WS ping every ~30s and arm a pong-timeout timer; on timeout, treat the channel as dead, emit a disconnect and reconnect (the existing generation/backoff machinery already drops stale attempts).
  2. Count failed auth attempts and stop retrying after 3 (mirroring the official cap), surfacing PushState::AuthRequired and requiring an explicit trigger (network restored / settings change / manual) to retry.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions