We run a live pub quiz app. A hundred phones in a room, one WiFi access point behind the bar, and a WebSocket that has to survive all of it. Drops are not an edge case here, they are Tuesday. So the client hook has the usual exponential backoff:
export function computeBackoff(attempt: number): number {
return Math.min(1000 * Math.pow(2, attempt), 30000)
}
Attempt 0 waits a second, attempt 4 waits sixteen, attempt 5 and beyond sit at the thirty second cap. Standard, boring, correct.
Then we started getting reports that felt wrong. A player's WiFi would blip for about two seconds, and their phone would sit on "Reconnecting" for what they described as "ages". The leaderboard had moved on by two questions before they came back.
The shape of the bug
The reconnect was being scheduled from the socket's onclose handler, and onclose needed to know the current status before deciding what to do. If we were already in the error state or already on the polling fallback, we m
Discussion
Your thoughts matter!
Your input is valuable—be the first to share it!