How a pub quiz app fixed WebSocket reconnects that left players stuck for ages
A live pub quiz platform serving around 100 simultaneous players over a single venue WiFi discovered that brief two-second connection drops were causing phones to show 'Reconnecting' for far longer than expected. The root cause was a stale closure bug: the WebSocket onclose handler was reading React state inside a setState updater, which delayed side effects like scheduling a reconnect until after reconciliation. The fix involved mirroring status into a React ref so the handler could read current state and act on it immediately, outside React's update cycle. Separately, the polling fallback interval was doubled from five to ten seconds after engineers calculated that 100 phones polling every five seconds generated roughly 1,200 requests per minute from one IP address, exceeding rate limits and knocking out the entire venue. The team accepted slightly stale data in degraded mode as a deliberate trade-off, reasoning that a lagging leaderboard is less harmful than a complete service outage.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in