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).
We carry a local patch on
RpcClientin 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
makeProtocolSocketmakePingerwrites a ping every 5 seconds. It fails the socket withSocketReadError("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:
Is an option on
makeProtocolSocketthe shape you'd want, or would you prefer something else, such as a singlepingTimeoutduration? Happy to send the PR in whichever shape you pick. The current patch, against 4.0.1, is here (makePinger).