New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http: Client hangs forever on 101 Status Code #44988
Comments
Go's http client handles http 101 and upgrades the connection to TCP/websocket. |
@AlexRouSg So the best is to hang? if it is no longer http protocol why not returning an error? the consequence of your statement is: all Go http clients, are vulnerable to DoS if the server (or someone poisoning the HTTP response) returns 101 status code, is that really what you meant? |
According to https://golang.org/pkg/net/http/#Client the timeout should include reading the body of the response |
At the very least, if a 101 Switching Protocols response disables the timeout that should be documented. |
Maybe the Transport could return an error if it sees a 101 response code to a request that lacked an Upgrade header. That wouldn't break existing websockets clients and I think might even be required to get a 101 response anyway. |
same issue. If the server doesn't send anything, the client hangs forever, and the program never exit. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I ran the following script locally, it takes forever, do not run that script on the playground because it may be killed by the sandbox as it takes forever.
https://play.golang.org/p/oUNf5aEleAr
What did you expect to see?
Timeout arguments to be enforced.
What did you see instead?
It takes forever.
IMPORTANT
About my title, well... I am not sure, somebody(Jorik) on gophers.slack.com noticed that the server was replying with a 101 status code on Firefox, not sure if that's the reason, in Chrome we don't get such 101 HTTP status, it just hangs. I don't know if httpClient gets such 101 status, all I know is it hangs, so if the reason is 101 Status code, then the title is appropriate, otherwise the title is misleading.
Update
A user(Nils Preuschoff) in that slack channel pointed me at a modified snippet:
https://play.golang.org/p/FPb2i0h--z6
It proves that indeed the faulty behaviour happens on Status Code 101, showing the HTTP status code 101 is the last event prior to hanging on ioutil.ReadAll(), is this a bug on Go? I am setting the timeout on both, header and response body, it should be honored, right?
Update2
Here I attach the equivalent fasthttp snippet doing a request to the same host, I used the default timeout settings from fasthttp to keep it simple, fasthttp, same as http package, has defaults timeouts values greater than 0 (no timeout), fasthttp returns immediately, while the http package hangs forever ...
https://play.golang.org/p/lq8FkgP7oJp
The text was updated successfully, but these errors were encountered: