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: verify Transport discards HTTP/1.x connections upon request timeout #23399
Comments
I was able to reproduce that if a Client request establishes a connection to a host, but the request times out, the connection is cached. However, IMO I don't see why this behavior is undesirable or unexpected. If a connection is successfully established, I don't think it should be discarded just because a request happens to take a long time. If there's nothing wrong with the connection, why not keep it. If the first request that uses a connection times out, I agree there's a high likelihood that future requests will also timeout, but at least we would have the efficiency of the cached connection. The code included by the OP is incomplete (@winworm , what is
|
thanks to meirf ,Mainly because in some special cases, the client set the timeout specified, the client did not send the specified protocol data to the server (such as bandwidth limitations caused by the server did not receive), the server will continue to maintain the connection until the server set the timeout time (this time is greater than the client timeout setting). So we want the client to be able to control whether or not to close the connection over time and not into the pool. |
Change https://golang.org/cl/123435 mentions this issue: |
I investigated this and wrote some tests (https://go-review.googlesource.com/c/go/+/123435) but was not able to reproduce. It seems to be doing the correct thing and closing the connection on timeout. I'm going to close this. Also, unrelated: the code |
For #23399 Change-Id: I9bc7c21fda6bfa89af2e7656e5c85aa9edd4f29e Reviewed-on: https://go-review.googlesource.com/123435 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Change https://golang.org/cl/123435 seems to broke all.bash occasionally both on amd64 and arm64. 23:07:24 2018/07/17 22:07:21 http: panic serving 127.0.0.1:55952: Fail in goroutine after TestClientTimeoutKillsConn_AfterHeaders has completed Logs on arm64: 13:10:14 --- FAIL: TestClientTimeoutKillsConn_AfterHeaders (0.06s) |
@erifan if you haven't already, best to create a new issue instead of continuing the conversation here since the problems are different. This issue is about validating that Client.Timeout closes connections. The new separate issue would be about those validation tests being flaky. |
It was flaky on slower machines. Per report at #23399 (comment) Change-Id: I7cab02821f78b5ce02ea51089d7eb51723f9705f Reviewed-on: https://go-review.googlesource.com/124835 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
@meirf OK, I'll do it in the future. I did not study this issue, but found that the change was cited here, so I thought it was the same question. Excuse me. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
Does this issue reproduce with the latest release?
no
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/git/go"
GORACE=""
GOROOT="installed/go"
GOTOOLDIR="/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build331671955=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
use client = &http.Client{Transport: transport, Timeout: 60} to invoke a http request
when timeout of this request has err info "Client.Timeout exceeded while awaiting headers" ,
it seems not close the connection after timeout.
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
client = &http.Client{Transport: transport, Timeout: 60}
resp, err := client.Do(req)
if nil != err {
logger.Errorf("traceId={%s},clientDoError={%s}", speech.TraceId, err.Error())
return respText
}
defer resp.Body.Close()
What did you expect to see?
when timeout occur ,should close the connection, not cache the timeout connection
What did you see instead?
the connection is not closed when timeout
The text was updated successfully, but these errors were encountered: