Closed
Description
It looks like there is odd logic both in http.Client and http.Server which in couple trigger really undesired behaviour.
- http.Server.Shutdown does not exit until there are any connections not in IDLE state, including connections in NEW state. NEW connections really do not significantly differ from IDLE. Both of them are not processing any requests, either already, or yet.
- http.Client creates new connection in case when there are no more IDLE connections in the pool, but when connection is established, it realises that other IDLE connection already appeared in the pool, and it prefers existing IDLE connection over newly created one. Just created connection is put to the idle connections pool, but there were no any requests sent over it. http.Server treats such connections as NEW and waits while client sends a request before shutting down.
What version of Go are you using (go version
)?
go version go1.8.3 linux/amd64
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/media/psf/Home/Documents/Work/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build834255989=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
[Example 1] https://play.golang.org/p/l22PCUvqpf
- Create and start http.Server
- Make a TCP connection to it
- Do no send any data to the connection
- Shutdown server
[Example 2] https://play.golang.org/p/JrZPNM3cn7
- Create http.Client
- Create http.Server
- Send a bunch of requests to server via http.Client
- Stop the server
- Go to 2
What did you expect to see?
- Example 1: http.Server.Shutdown do not wait for connections which are not active yet. NEW connections are logically the same as IDLE connections, there is no need to wait for them.
- Example 1: HTTP server with default parameters has reasonable timeouts which are suitable for most non-advanced cases.
- Example 2: HTTP client sends the request which triggered creation of a new connection, over that just created connection. There is no any reason to suddenly switch to another connection.
What did you see instead?
- Example 1: HTTP server closes only IDLE connections and waits until all connections become IDLE or closed.
- Example 1: HTTP server with default parameters has infinite timeouts which makes it practically unusable.
- Example 2: HTTP client puts just created connection to IDLE connections pool without sending requests to it.