Skip to content

RpcClient: tolerate more than one missed pong on the socket protocol #8774

Description

@juliusmarminge

We carry a local patch on RpcClient in T3 Code, a WebSocket RPC client that keeps long-lived subscriptions open from desktop, web and mobile. One part of it we'd like upstream so we can drop it. Opening an issue first because it needs an API choice.

Tolerate more than one missed pong on makeProtocolSocket

makePinger writes a ping every 5 seconds. It fails the socket with SocketReadError("ping timeout") as soon as one pong hasn't arrived by the next tick, so a single late pong is fatal about 5–10 seconds after the last one. On mobile networks, and on a busy server (a long synchronous handler, a large frame being written), one late pong is common. Each time, every in-flight request and subscription fails and the client reconnects. We saw clients loop through reconnects while the server was briefly stalled.

Our patch counts missed pongs and keeps sending pings. It only opens the timeout latch after 3 consecutive misses, and any pong resets the count.

A possible API, with defaults unchanged:

RpcClient.makeProtocolSocket({
  pingInterval?: Duration.Input      // default "5 seconds"
  maxMissedPongs?: number            // default 1 (today's behavior)
})

Is an option on makeProtocolSocket the shape you'd want, or would you prefer something else, such as a single pingTimeout duration? Happy to send the PR in whichever shape you pick. The current patch, against 4.0.1, is here (makePinger).

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions