Skip to content

Commit 6909a69

Browse files
bazel-iobenjaminp
andauthored
[9.0.0] enable gRPC keepalive by default (#27676)
The keepalive is critical for detecting load balancers and other network middlemen that like to silently drop connection data after periods of idleness. Closes #27473. PiperOrigin-RevId: 832225094 Change-Id: I023e34377a19d41bd810b8c3632bf46bea2fe81f Commit d368478 Co-authored-by: Benjamin Peterson <benjamin@engflow.com>
1 parent 60c5a03 commit 6909a69

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/main/java/com/google/devtools/build/lib/authandtls/AuthAndTLSOptions.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,15 @@ public class AuthAndTLSOptions extends OptionsBase {
116116

117117
@Option(
118118
name = "grpc_keepalive_time",
119-
defaultValue = "null",
119+
defaultValue = "60s",
120120
converter = DurationConverter.class,
121121
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
122122
effectTags = {OptionEffectTag.UNKNOWN},
123123
help =
124124
"""
125125
Configures keep-alive pings for outgoing gRPC connections. If this is set, then Bazel
126126
sends pings after this much time of no read operations on the connection, but
127-
only if there is at least one pending gRPC call. Times are treated as second
128-
granularity; it is an error to set a value less than one second. By default,
129-
keep-alive pings are disabled. You should coordinate with the service owner
130-
before enabling this setting. For example to set a value of 30 seconds to this
131-
flag, it should be done as this `--grpc_keepalive_time=30s`.
127+
only if there is at least one pending gRPC call. The value 0 disables the keep-alives.
132128
""")
133129
public Duration grpcKeepaliveTime;
134130

src/main/java/com/google/devtools/build/lib/authandtls/GoogleAuthUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.devtools.build.lib.authandtls;
1616

17+
import static java.util.concurrent.TimeUnit.NANOSECONDS;
18+
1719
import com.github.benmanes.caffeine.cache.Cache;
1820
import com.google.auth.Credentials;
1921
import com.google.auth.oauth2.GoogleCredentials;
@@ -55,7 +57,6 @@
5557
import java.util.Map;
5658
import java.util.Optional;
5759
import java.util.concurrent.Executor;
58-
import java.util.concurrent.TimeUnit;
5960
import javax.annotation.Nullable;
6061

6162
/** Utility methods for using {@link AuthAndTLSOptions} with Google Cloud. */
@@ -89,9 +90,9 @@ public static ManagedChannel newChannel(
8990
.executor(executor)
9091
.negotiationType(
9192
isTlsEnabled(target) ? NegotiationType.TLS : NegotiationType.PLAINTEXT);
92-
if (options.grpcKeepaliveTime != null) {
93-
builder.keepAliveTime(options.grpcKeepaliveTime.toSeconds(), TimeUnit.SECONDS);
94-
builder.keepAliveTimeout(options.grpcKeepaliveTimeout.toSeconds(), TimeUnit.SECONDS);
93+
if (options.grpcKeepaliveTime != null && !options.grpcKeepaliveTime.isZero()) {
94+
builder.keepAliveTime(options.grpcKeepaliveTime.toNanos(), NANOSECONDS);
95+
builder.keepAliveTimeout(options.grpcKeepaliveTimeout.toNanos(), NANOSECONDS);
9596
}
9697
if (interceptors != null) {
9798
builder.intercept(interceptors);

0 commit comments

Comments
 (0)