From ec124ff9e0a08573e012cbd73709030398e8b0c1 Mon Sep 17 00:00:00 2001 From: Soheil Fakour Date: Thu, 29 Oct 2026 07:12:11 +0330 Subject: [PATCH] WebSocket transport: Treat normal close frames as io.EOF (#7236) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/XTLS/Xray-core/issues/7235#issuecomment-6353389899 --------- Co-authored-by: 风扇滑翔翼 --- transport/internet/websocket/connection.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/transport/internet/websocket/connection.go b/transport/internet/websocket/connection.go index 26082fc68..4ce85df2b 100644 --- a/transport/internet/websocket/connection.go +++ b/transport/internet/websocket/connection.go @@ -46,6 +46,12 @@ func (c *connection) Read(b []byte) (int, error) { for { reader, err := c.getReader() if err != nil { + // A close frame with a normal status (1000) or no status (1005) ends + // the byte stream the same way a FIN does, so report io.EOF instead + // of an error. Other close codes keep their error semantics. + if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) { + return 0, io.EOF + } return 0, err }