-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: TCP connection is not closed after http client makes a https request via a http proxy server which doesn't response #28012
Comments
/cc @bradfitz |
any update ? the same issue |
I believe I'm also seeing this issue, with 1.13.4 on Linux. With a simple client like this, and using it to make a dumb GET request to some server:
If the server doesn't respond within 30 seconds, the client gets a timeout error as expected. But, Go does not close the underlying TCP connection to the server. If the client keeps retrying, unfortunately its subsequent requests get queued on the same TCP connection. If the server doesn't close the connection, or perhaps if there's an underlying TCP connection (e.g. connectivity) break which means the client and server aren't actually communicating, the client doesn't redial to establish a new connection, at least perhaps until the local kernel socket send buffer is full, or there's a TCP keepalive timeout, or something (conjecture). You can see this when it happens because Setting IMO it would make more sense for Go to abandon and close the underlying TCP connection if an HTTP timeout has occured on it. @bradfitz @katiehockman any thoughts? |
Same issure here with go 1.13.5, tcp connection is not closed, even when i use the new |
I also tried messing around with casting the returned error to a |
Setting It really depends on the server connecting to. When the HTTPD is a golang http server (i.e caddy) we get the issue that the tcp connections are never closed. When i connect to a haproxy or something else it gets closed (maybe also from server side). Maybe it's also related to HTTP2 I will now set req.Close = true to be sure it gets closed. I can reproduce this via this code and this http destination:
@bradfitz any thoughts why the connection will stay open? if we change the http destianation to www.google.com it is closed fine. Shouldnt the ctx cancel close it as well? |
Change https://golang.org/cl/210286 mentions this issue: |
@bradfitz I've confused this issue which I now realise was originally opened for proxy CONNECTs with a different but similar issue that I encountered when not using a proxy. Your CL could be good for the original issue but probably not for mine. Sorry. Should I open a separate issue or can both be dealt with here? |
Separate issue, please. |
I also run into this without using a proxy @jim-minter Can you link the new issue? My example code should also be there.. |
New issue is #36026 - thanks again and sorry for the noise! |
Change https://golang.org/cl/210857 mentions this issue: |
…HTTPSConnectTimeout The use of a timeout in this test caused it to be flaky: if the timeout occurred before the connection was attempted, then the Accept call on the Listener could hang indefinitely, and its goroutine would not exit until that Listener was closed. That caused the test to fail. A longer timeout would make the test less flaky, but it would become even slower and would still be sensitive to timing. Instead, replace the timeout with an explicit Context cancellation after the CONNECT request has been read. That not only ensures that the cancellation occurs at the appropriate point, but also makes the test much faster: a test run with -count=1000 now executes in less than 2s on my machine, whereas before it took upwards of 50s. Fixes #36082 Updates #28012 Change-Id: I00c20d87365fd3d257774422f39d2acc8791febd Reviewed-on: https://go-review.googlesource.com/c/go/+/210857 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.11 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hoozecn/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH=":/usr/local/share/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bs/828m4j8s3035x5z5hbp_fc6m0000gn/T/go-build954257246=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
I created a simple socket server which accept tcp connections without doing anything with the following code:
And create a http client with timeout
What did you expect to see?
The tcp connection to 127.0.0.1:12346 should be closed after timeout
What did you see instead?
The tcp connection stays there and a go routine leaks until the proxy server shutdown
The text was updated successfully, but these errors were encountered: