-
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
proposal: add httputil.TCPKeepAliveListener #23378
Comments
Alternatively, add something to net.TCPListener so it does this automatically upon Accept. |
Or do this by default. #23459. |
On hold for #23459. |
Just checking in here to see, with #23459 being closed, if this can move forward or be discussed further. |
Seems like #23459 only added a default keepalive for connections created with net.Dial(er). If we wanted to obviate this issue in a similar way, we'd need to do the analogous thing for net.Listen and friends. Am I missing something? |
Yeah, we could do this by default for Listen too, but then we should add a way to disable it for people using https://golang.org/pkg/net/#ListenConfig by adding a KeepAlive field to ListenConfig like the Dialer has: https://golang.org/pkg/net/#Dialer.KeepAlive @cespare, you want to do that? |
@bradfitz sure, will do. |
Change https://golang.org/cl/170678 mentions this issue: |
@costela thanks! |
I just stumbled upon this... I think it would be advisable, for uniformity, to use the same duration internally as the one used by Dialer (https://golang.org/src/net/dial.go#L427). I'm not saying the value needs to be necessarily 15s (although that was debated a while back and agreed upon, see #23459), but they should be the same value (and, as discussed in #23459, I think this value should not be part of the public API). |
This was proposed and put on hold and then committed without the proposal being approved. Are we OK with this API? |
The new field in ListenConfig has the same name, type, and default as in Dialer, so approving proposal. |
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:
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:
https://github.com/search?q=tcpKeepAliveListener+language%3Ago&ref=simplesearch&type=Code&utf8=%E2%9C%93
Two questions:
The text was updated successfully, but these errors were encountered: