Skip to content

yandex: reduce reconnect churn (participant pile-up) and close stale conns - #55

Open
D13tre33 wants to merge 1 commit into
p1neappleXpress:mainfrom
D13tre33:tune/yandex-reconnect-backoff
Open

yandex: reduce reconnect churn (participant pile-up) and close stale conns#55
D13tre33 wants to merge 1 commit into
p1neappleXpress:mainfrom
D13tre33:tune/yandex-reconnect-backoff

Conversation

@D13tre33

Copy link
Copy Markdown

Summary

Follow-up to #54 (which fixes the yandex transport's handshake race).
With that race fixed, sessions establish reliably, but I noticed
something else while watching a live exit node for a while afterward:
a session that fully succeeds still eventually gets an explicit
server-side disconnect (disconnectReason code 4007, "drop") after
roughly 60-90 seconds.

While digging into that (not fixed here - see below), I logged the
server's auth/connectState messages, which list the doc room's
current participants. Every WebSocket reconnect - even ones that fail
fast - registers as a brand new "Anonymous" participant server-side
(Yandex assigns its own participant id per connection and ignores our
client-side user.id). During a failure streak I saw 2-3 simultaneous
ghost participants pile up in the same room from nothing but our own
reconnect attempts.

This PR doesn't fix the underlying 4007/drop behavior (that looks
like it's coming from Yandex's own collab-session participant limits,
not something client-side code controls), but it does reduce how fast
our own retries can pile up participants:

  • reconnectBackoff()'s floor goes from 500ms to 1.5s and its cap
    from 15s to 30s. Successful connects never hit backoff at all, so
    this only affects failure streaks.
  • The main read loop's error branch now calls conn.Close() instead
    of leaving the socket for the runtime to clean up whenever.

Test plan

  • CGO_ENABLED=0 go build succeeds (via the repo's Dockerfile)
  • Deployed as the exit-node profile; confirmed in logs that the
    new backoff floor/cap take effect on reconnect

Two small reconnect-hygiene fixes:

- Every WebSocket reconnect registers as a brand new participant in
  the doc's collab room server-side, regardless of client-side userID
  reuse (confirmed by logging the server's participant-list messages
  during a failure streak - saw 2-3 simultaneous "ghost" participants
  pile up across repeated reconnects). A tight failure loop churns
  through these fast. Raised reconnectBackoff()'s floor from 500ms to
  1.5s and its cap from 15s to 30s to slow that down; this doesn't
  touch steady-state throughput since successful connects never hit
  backoff.

- The main read loop's error branch never called conn.Close() on the
  WebSocket, leaving the local socket to clean up whenever the runtime
  got around to it instead of promptly.
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