-
Notifications
You must be signed in to change notification settings - Fork 4.5k
grpc: disable and document overrides of OS default TCP keepalive by Go #6672
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
Changes from all commits
9fe3359
3e5bf86
0b94503
3138142
5993a5f
06962e3
50615a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,9 @@ func dial(ctx context.Context, fn func(context.Context, string) (net.Conn, error | |
if networkType == "tcp" && useProxy { | ||
return proxyDial(ctx, address, grpcUA) | ||
} | ||
return (&net.Dialer{}).DialContext(ctx, networkType, address) | ||
// KeepAlive is set to a negative value to prevent Go's override of the TCP | ||
// keepalive time and interval; retain the OS default. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this comment is technically correct, I'm not sure this is what you intended and I think the comment could be more clear: the default on linux is to disable keepalives unless opted in via SO_KEEPALIVE, which then uses the os-level keepalive configuration. At least this is different from Java and what Eric proposed in #6250 (comment), which would be to set SO_KEEPALIVE to true unconditionally. This could be done by adding something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm, I believe you are right. We were under the impression that keepalives were always enabled and that a negative value would not disable them, but would use the OS defaults for the timers. However, this doesn't call https://go.dev/src/net/tcpsock.go#L238 And they set https://go.dev/src/net/sockopt_posix.go#L116 So presumably not doing that means keepalives will be disabled otherwise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of unconditionally enabling keepalives via Dialer control then?
I think we should try to do that before the release. edit: nevermind, just saw your comment on #6250 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A little bit more thought is required I guess. We do set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it appears that the proposal mentioned here has made significant progress and has a pending change. This would allow us to disable TCP keepalive or use OS defaults with a simple API. We would have to wait for a new Go version though, to be able to use this and would be a while until that Go version becomes the least supported Go version for grpc. |
||
return (&net.Dialer{KeepAlive: time.Duration(-1)}).DialContext(ctx, networkType, address) | ||
JaydenTeoh marked this conversation as resolved.
Show resolved
Hide resolved
JaydenTeoh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func isTemporary(err error) bool { | ||
|
Uh oh!
There was an error while loading. Please reload this page.