Skip to content

rpc: use library Close helper for websocket disconnect#20913

Merged
yperbasis merged 2 commits into
mainfrom
yperbasis/followup20788
Apr 29, 2026
Merged

rpc: use library Close helper for websocket disconnect#20913
yperbasis merged 2 commits into
mainfrom
yperbasis/followup20788

Conversation

@yperbasis

Copy link
Copy Markdown
Member

Summary

Follow-up to #20788. Address review feedback from @anacrolix:

I thought there was a helper in the websocket library for this so you don't need to spin up a bunch of timers and goroutines?

The coder/websocket Conn.Close(code, reason) method already performs the close handshake with bounded internal timeouts (5s write, 5s read), so the manual goroutine + timer plumbing in wsConnAdapter.Close is redundant. Replace it with a direct call.

The existing TestWebsocketServerGracefulClose test still passes — clients see a clean StatusNormalClosure (1000) instead of StatusAbnormalClosure (1006).

Test plan

  • go test ./rpc/ -run Websocket — all pass
  • make lint — clean

🤖 Generated with Claude Code

Replace the manual goroutine + timer pattern in wsConnAdapter.Close with
a direct call to coder/websocket Conn.Close(StatusNormalClosure, ""),
which already performs the close handshake with bounded internal
timeouts (5s write, 5s read). Follow-up to #20788.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@Giulio2002 Giulio2002 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — small, obvious cleanup: use the websocket library's close helper directly instead of duplicating custom close-handshake logic here.

@yperbasis yperbasis added this pull request to the merge queue Apr 29, 2026
Merged via the queue into main with commit d7b2a63 Apr 29, 2026
38 checks passed
@yperbasis yperbasis deleted the yperbasis/followup20788 branch April 29, 2026 19:16
lupin012 added a commit that referenced this pull request Apr 29, 2026
#20913 replaced the two-goroutine async close with a direct
conn.Close() call, noting that coder/websocket already handles the
close handshake with bounded internal timeouts (5s write, 5s read).
Align our branch to avoid re-introducing the goroutines when merging.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants