-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: fix docs on Transport connection reuse specifics #22954
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
Comments
What answer would you like to see? Do you want to control the number of outgoing connections?
… On 1 Dec 2017, at 16:53, LoinLiao ***@***.***> wrote:
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.7 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env)?
What did you do?
package main
import (
"time"
"fmt"
"io/ioutil"
"net/http"
)
func main() {
resp, err := http.Get("http://127.0.0.1:8588")
if err != nil {
panic(err)
}
_, err = ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
resp2, err := http.Get("http://127.0.0.1:8588")
if err != nil {
panic(err)
}
_, err = ioutil.ReadAll(resp2.Body)
if err != nil {
panic(err)
}
fmt.Println("before time sleep")
time.Sleep(time.Second * 35)
}
in GO net/http Response Body annotation says:
It is the caller's responsibility to close Body. The default HTTP client's Transport does not attempt to reuse HTTP/1.0 or HTTP/1.1 TCP connections ("keep-alive") unless the Body is read to completion and is closed.
yeah, it say we must read body complete AND close body.
in the above code, after read resp.Body I don't close the resp.Body. so, the http client should't reuse the tcp connection. so there will be two tcp connection handshark in wireshark, but I only see ONE.
so, maybe the net/http's comment has something wrong?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
What makes me wonder is resp2 should not reuse tcp connection because I don't call resp.Body.Close(). so I will see TWO tcp handshake. but I only see ONE. so resp reuse tcp connection created by resp, but i don't call resp.Body.Close().
|
I'll update it to something slightly vaguer and less promise-sounding. The reality is that it'll do it if it can. |
Change https://golang.org/cl/86276 mentions this issue: |
What version of Go are you using (
go version
)?go version go1.7 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
in GO net/http Response Body annotation says:
yeah, it say we must read body complete AND close body.
in the above code, after read resp.Body I don't close the resp.Body. so, the http client should't reuse the tcp connection. so there will be two tcp connection handshark in wireshark, but I only see ONE.
so, maybe the net/http's comment has something wrong?
thank you.
The text was updated successfully, but these errors were encountered: