Skip to content

fix(listen): stop reconnecting when a websocket pong is a little late - #473

Open
alexluong wants to merge 1 commit into
mainfrom
fix/websocket-keepalive
Open

alexluong wants to merge 1 commit into
mainfrom
fix/websocket-keepalive

Conversation

@alexluong

Copy link
Copy Markdown
Collaborator

hookdeck listen drops a healthy connection whenever the server's reply to a ping (pong) is more than about a second late. Users on slower or busier networks then see "Connection lost, reconnecting..." every few minutes.

Why: the client pings every 9s and drops the connection if no pong arrives within 10s of the previous one. That leaves about 1s of slack:

Before: ping every 9s, drop 10s after the last pong

  0s     pong received ──────────────── deadline 10s
  9s     ping sent
  10s    ✗ deadline hit, connection dropped   ("Connection lost, reconnecting...")
  10.5s  pong arrives, too late

After: ping every 10s, drop 30s after the last frame of any kind

  0s     pong received ─────────────────────────────────────── deadline 30s
  10s    ping sent
  10.5s  pong arrives ✓ deadline moves to 40.5s
Before After
Ping every 9s 10s
Drop after 10s without a pong 30s without any frame
Slack for a late pong ~1s ~20s
Incoming events keep it alive no yes
Old socket on reconnect left open until the server cleans it up closed

Changes (pkg/websocket/client.go):

  1. Pong wait 10s → 30s; ping every 10s.
  2. Any incoming frame renews the read deadline.
  3. Close the old socket before reconnecting.

Tests: a busy connection with late pongs stays up; the socket closes after a read timeout; new defaults. All three fail on the old code.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant