Skip to content

rpc: send clean close frame on websocket disconnect#20788

Open
Sahil-4555 wants to merge 6 commits intoerigontech:mainfrom
Sahil-4555:rpc/fix-ws-abnormal-closure
Open

rpc: send clean close frame on websocket disconnect#20788
Sahil-4555 wants to merge 6 commits intoerigontech:mainfrom
Sahil-4555:rpc/fix-ws-abnormal-closure

Conversation

@Sahil-4555
Copy link
Copy Markdown
Contributor

Currently, when a WebSocket connection is closed by the RPC server, the underlying TCP connection gets torn down immediately without sending a final WebSocket Close frame. Because of this abrupt teardown, clients connected to the node experience an abnormal closure (error code 1006) instead of a clean, normal disconnect (error code 1000).

This PR fixes that behavior by explicitly sending a clean 1000 normal closure frame right before terminating the connection. It uses the Close() method from the coder/websocket library to safely transmit this control frame.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make RPC server–initiated WebSocket disconnects appear as a clean, normal WebSocket closure (1000) to peers, instead of an abnormal closure (1006), by explicitly sending a Close control frame before tearing down the connection.

Changes:

  • Send a WebSocket Close frame (StatusNormalClosure) in websocketCodec.Close() prior to shutting down the JSON codec and ping loop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rpc/websocket.go Outdated
Comment thread rpc/websocket.go Outdated
Comment thread rpc/websocket.go Outdated
Comment thread rpc/websocket.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rpc/websocket.go Outdated
Comment thread rpc/websocket_test.go
yperbasis
yperbasis previously approved these changes Apr 27, 2026
@yperbasis
Copy link
Copy Markdown
Member

@Sahil-4555 fix lint plz

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rpc/websocket.go Outdated
Comment thread rpc/websocket.go Outdated
Comment thread rpc/websocket_test.go Outdated
@yperbasis yperbasis dismissed their stale review April 27, 2026 07:19

let's address copilot's comments

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants