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

proposal: add httputil.TCPKeepAliveListener #23378

kevinburke opened this Issue Jan 8, 2018 · 3 comments


None yet
4 participants
Copy link

kevinburke commented Jan 8, 2018

Currently there's no easy way for users to recreate the behavior
present in http.ListenAndServeTLS, short of copying the
tcpKeepAliveListener out of the net/http package. As a refresher, that's this:

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
	addr := srv.Addr
	if addr == "" {
		addr = ":https"

	ln, err := net.Listen("tcp", addr)
	if err != nil {
		return err

	defer ln.Close()

	return srv.ServeTLS(tcpKeepAliveListener{ln.(*net.TCPListener)}, certFile, keyFile)

Making that package public would make it easy for people to mirror the behavior in that function. In my case, I like to open a socket, log a message, and then start the server, as the server blocks until shutdown.

It also seems like a lot of people are trying to copy it, scan the results here:

Two questions:

  • We can't load it in net/http because that would involve an import cycle. Is a copy okay?
  • the keep-alive period is hard coded to 3 minutes. Should we allow users to configure this? The zero value can conceivably be valid.

@gopherbot gopherbot added this to the Proposal milestone Jan 8, 2018

@gopherbot gopherbot added the Proposal label Jan 8, 2018


This comment has been minimized.

Copy link

bradfitz commented Jan 8, 2018

Alternatively, add something to net.TCPListener so it does this automatically upon Accept.


This comment has been minimized.

Copy link

rsc commented Jan 22, 2018

Or do this by default. #23459.


This comment has been minimized.

Copy link

rsc commented Jan 22, 2018

On hold for #23459.

@rsc rsc added the Proposal-Hold label Jan 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment