Repository navigation
WebSocket transport: Treat normal close frames as io.EOF - #7236
Merged
Merged
Conversation
A close frame with code 1000 (normal) or 1005 (no status) ends the byte stream the same way a FIN does, but connection.Read returned gorilla's *websocket.CloseError to its callers. VLESS and Trojan carry payload without framing, so a response copy ended with that error; the outbound dispatch treats it as a failure and interrupts the pipe, dropping the tail that the inbound had not read yet. Map normal-closure and no-status close frames to io.EOF. Other close codes keep their error semantics. Fixes XTLS#7235
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Romaxa55
pushed a commit
to Romaxa55/Xray-core
that referenced
this pull request
Nov 2, 2026
gorilla/websocket answers the peer's close frame with its own and then fails every write with the sentinel ErrCloseSent. The outbound handler treats any error but EOF as a broken link and interrupts the pipe, dropping the response the reader has not taken yet. After the close handshake the stream is over: report io.EOF, as Read does for a normal close since XTLS#7236.
Romaxa55
pushed a commit
to Romaxa55/Xray-core
that referenced
this pull request
Nov 2, 2026
Fixes XTLS#7235 (comment) --------- Co-authored-by: 风扇滑翔翼 <[email protected]>
Romaxa55
pushed a commit
to Romaxa55/Xray-core
that referenced
this pull request
Nov 2, 2026
gorilla/websocket answers the peer's close frame with its own and then fails every write with the sentinel ErrCloseSent. The outbound handler treats any error but EOF as a broken link and interrupts the pipe, dropping the response the reader has not taken yet. After the close handshake the stream is over: report io.EOF, as Read does for a normal close since XTLS#7236.
black-raison-detre
added a commit
to black-raison-detre/Xray-core
that referenced
this pull request
Nov 7, 2026
Backport upstream XTLS#7225, XTLS#7327, XTLS#7236, and XTLS#7291 onto the v26.7.11 maintenance branch with focused regression coverage. Co-authored-by: Codex <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
A WebSocket close frame with a normal status (1000) or no status (1005) ends the byte stream the same way a FIN does, but
connection.Readsurfaced gorilla's*websocket.CloseErrorto its callers.VLESS and Trojan carry payload without framing, so a response copy ended with that error.
app/proxyman/outbound.Handler.Dispatchtreats every error other thanio.EOFas a failure and callscommon.Interrupt, which releases the data still buffered in the pipe before the inbound has read it. The client gets a short response that ends with a normal FIN - silent truncation for HTTP/1.0 responses without Content-Length, and awebsocket: close 1000 (normal)line for every such connection.Fix: map
websocket.IsCloseError(err, CloseNormalClosure, CloseNoStatusReceived)toio.EOFinconnection.Read. Other close codes keep their error semantics. The same wrapper is used by the XHTTP browser dialer client (transport/internet/splithttp/browser_client.go), so that path inherits the fix.Fixes #7235.
Test record
Environment:
1b1647cd(v26.10.21), linux/amd64. The configs and scripts from the report used verbatim: target answersHTTP/1.0 200 OK+ 65536 body bytes without Content-Length, then closes; the client fetches through anhttpinbound -> VLESS/ws outbound.1b1647cdbba46a28GOMAXPROCS=1close 1000log linesclose 1000log linesThe byte counts above are from the runs saved for this report; a second base run produced the same shape (18/20 short) with a different byte split.
Unit tests (new
connection_test.go, real WebSocket server + the production wrapper): RED on base - close 1000 and 1005 come back aswebsocket: close 1000 (normal)/close 1005 (no status)instead ofio.EOF; GREEN with the fix. A 1001 (going away) control asserts that other close codes stay errors, before and after.go test ./transport/internet/...- 25 packages pass.go build ./...,gofmt,go vetclean.Known boundary: a close frame arriving in the middle of a fragmented message still surfaces as a close error, because that payload is genuinely incomplete; only a close after a complete message is remapped, which is the reported mechanism.