Repository navigation
Conversation
When the server answered 101 but a header check failed, Dial read up to 1024 bytes from the response body before returning. After a 101 the body is the upgraded connection, so a silent server made Dial wait for the 3 s timer. Close it instead and return an empty body; other statuses still return the first 1024 bytes.
This branch has not been deployed
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.
When the server answers
101 Switching Protocolsbut the handshake still fails, for example on an invalidSec-WebSocket-Acceptor a subprotocol the client did not offer,Dialnow closes the response body and returns at once.Previously, every
Dialthat failed after receiving a response read up to 1024 bytes of the response body for debugging, with a 3 second timer. After a 101 the body is the upgraded connection, not an HTTP body, so when the server sent nothing more, each of these failures took 3 seconds.For these failures the returned response keeps its status and headers, and
resp.Bodyis empty (http.NoBody). Failures with any other status are unchanged:resp.Bodyholds up to the first 1024 bytes, read with the same 3 second limit.The tradeoff: if a server answers 101 and then writes error text on the connection,
resp.Bodyno longer contains that text. Bytes after a 101 belong to the upgraded protocol, not to an HTTP body.TestDialFailedHandshakeBodycovers a 101 with an invalidSec-WebSocket-Acceptfrom a server that then stays silent (fails on master after 3.0 s; passes with this change in about 0 s against a 1 s limit) and a 403 whose body is still returned. Lint, race tests and the WASM test pass.Decision log
http.NoBodyinstead of a nilresp.Body: whenDialreturns a response with an error,resp.Bodyhas never been nil, so callers that read it need no new nil check.Dialdoc. Its text ("you can only read the first 1024 bytes of the body") stays true with an empty body.