Skip to content

Commit 480640d

Browse files
authored
alts: add experimental keepalive (#12076)
1 parent b88536a commit 480640d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

alts/src/main/java/io/grpc/alts/HandshakerServiceChannel.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.grpc.ClientCall;
2222
import io.grpc.ManagedChannel;
2323
import io.grpc.MethodDescriptor;
24+
import io.grpc.internal.GrpcUtil;
2425
import io.grpc.internal.SharedResourceHolder.Resource;
2526
import io.grpc.netty.NettyChannelBuilder;
2627
import io.netty.channel.EventLoopGroup;
@@ -45,6 +46,9 @@ static Resource<Channel> getHandshakerChannelForTesting(String handshakerAddress
4546
return new ChannelResource(handshakerAddress);
4647
}
4748

49+
private static final boolean EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS =
50+
GrpcUtil.getFlag("GRPC_EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS", false);
51+
4852
private static class ChannelResource implements Resource<Channel> {
4953
private final String target;
5054

@@ -57,12 +61,16 @@ public Channel create() {
5761
/* Use its own event loop thread pool to avoid blocking. */
5862
EventLoopGroup eventGroup =
5963
new NioEventLoopGroup(1, new DefaultThreadFactory("handshaker pool", true));
60-
ManagedChannel channel = NettyChannelBuilder.forTarget(target)
64+
NettyChannelBuilder channelBuilder =
65+
NettyChannelBuilder.forTarget(target)
6166
.channelType(NioSocketChannel.class, InetSocketAddress.class)
6267
.directExecutor()
6368
.eventLoopGroup(eventGroup)
64-
.usePlaintext()
65-
.build();
69+
.usePlaintext();
70+
if (EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS) {
71+
channelBuilder.keepAliveTime(10, TimeUnit.MINUTES).keepAliveTimeout(10, TimeUnit.SECONDS);
72+
}
73+
ManagedChannel channel = channelBuilder.build();
6674
return new EventLoopHoldingChannel(channel, eventGroup);
6775
}
6876

0 commit comments

Comments
 (0)