Skip to content

[Bug] WebSocket silently drops slow clients; client has no reconnection #8

Description

@dev-rkb

Description

Two related reliability issues:

  1. packages/server/game/hub.go:69-74 — When a client's Send
    channel is full, the hub closes the channel and removes the client
    from the room. The peer receives no error or game_over frame, so
    the UI freezes with no indication.

  2. packages/web/src/app/chess/page.tsx:31-71 — The frontend does
    not reconnect on socket close. After a network blip, the player must
    manually refresh the page to resume.

Proposed fix

Server:

  • Replace silent close with a WSMessage{Type: "disconnect", payload: {reason: "slow_consumer"}} sent best-effort before closing.
  • Add a pong handler and a read deadline on the websocket so dead
    connections are detected within ~60s instead of relying on the
    client's next write.

Client:

  • Extract the WebSocket effect into packages/web/src/hooks/useChessSocket.ts
    (the empty hooks/ dir already exists for this).
  • Implement exponential backoff reconnection (1s, 2s, 4s, 8s, cap at 30s).
  • On reconnect, resend the join frame; on receiving game_update for
    the same gameId, re-hydrate state.
  • Show a small "Reconnecting..." banner when readyState is not OPEN.

Acceptance criteria

  • A client whose Send buffer fills receives a disconnect frame
    before the connection closes
  • Refreshing the page mid-game is no longer required after a
    transient network blip; the board re-syncs within 30s
  • A useChessSocket hook exists under packages/web/src/hooks/

Files

  • packages/server/game/hub.go
  • packages/server/handler/websocket.go
  • packages/web/src/hooks/useChessSocket.ts (new)
  • packages/web/src/app/chess/page.tsx

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions