Skip to content

net/http: Keepalive connections are not terminated when server returns. #14927

Closed
@klauspost

Description

@klauspost

1. What version of Go are you using?

go version go1.6 windows/amd64 and go version go1.5.3 windows/amd64.

2. What operating system and processor architecture are you using?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=c:\gopath
set GORACE=
set GOROOT=c:\go
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1

3. What did you do?

Playground Reproduction (must be run locally)

The application creates an HTTP server in a separate goroutine.

This server is then shut down. Everything should be unreferenced by this point. Another server is created in a new goroutine.

It seems that unless there is data written to the ResponseWriter, the old handler functions are used, even for the new server, which has a separate http.ServeMux and http.Server.

It does not matter even if there is minutes between the old server being stopped and the new one being created.

This is not a client specific issue, just so you do not spend time investigating that. This also happens with a browser, which is how the issue was discovered.

4. What did you expect to see?

2016/03/23 11:51:18 Starting server on localhost:56000
2016/03/23 11:51:18 1 server should give redirect to: http://google.com
2016/03/23 11:51:19 1 Redirect to http://google.com
2016/03/23 11:51:19 1 Closing auth server
2016/03/23 11:51:19 1 Closed server
2016/03/23 11:51:19 --- SERVER 1 STOPPED
2016/03/23 11:51:20 Starting server on localhost:56000
2016/03/23 11:51:20 2 server should give redirect to: http://yahoo.com
2016/03/23 11:51:20 2 Redirect to http://yahoo.com
2016/03/23 11:51:20 2 Redirect to http://yahoo.com
2016/03/23 11:51:20 2 Write destination: http://yahoo.com
2016/03/23 11:51:21 2 Redirect to http://yahoo.com

After server "1" is stopped, there should be no logging lines prefixed with "1", and the handler should always print "yahoo.com".

5. What did you see instead?

2016/03/23 11:51:18 Starting server on localhost:56000
2016/03/23 11:51:18 1 server should give redirect to: http://google.com
2016/03/23 11:51:19 1 Redirect to http://google.com
2016/03/23 11:51:19 1 Closing auth server
2016/03/23 11:51:19 1 Closed server
2016/03/23 11:51:19 --- SERVER 1 STOPPED
2016/03/23 11:51:20 Starting server on localhost:56000
2016/03/23 11:51:20 2 server should give redirect to: http://yahoo.com
2016/03/23 11:51:20 1 Redirect to http://google.com
2016/03/23 11:51:20 1 Redirect to http://google.com
2016/03/23 11:51:20 1 Write destination: http://google.com
2016/03/23 11:51:21 2 Redirect to http://yahoo.com

Since everything is created "cleanly" in the goroutine AFAICT, there should not be any was for server "1" handler functions to be used.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions