Hi, we have a bidirectional java gRPC server & we are using NettyServerBuilder to configure the server. I have read all the docs in order to implement the ping/pong mechanism for the gRPC connection. Below is our server config
server code:
((NettyServerBuilder) serverBuilder)
.executor(executor)
//Allow client pings even if no ongoing calls are happening (default is false)
.permitKeepAliveWithoutCalls(true)
//Least keep alive time allowed for clients to configure
.permitKeepAliveTime(10,TimeUnit.SECONDS)
//How long a channel can stay idle (idle means no pings & messages received)
.maxConnectionIdle(5,TimeUnit.SECONDS)
//How long a channel can stay at all (even if not idle)
.maxConnectionAge(1,TimeUnit.MINUTES)
//Grace period after the channel ends
.maxConnectionAgeGrace(10,TimeUnit.SECONDS)
//Max payload size
.maxInboundMessageSize(Integer.MAX_VALUE)
//Max headers size
.maxInboundMetadataSize(Integer.MAX_VALUE);
}
client code:
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 50004)
.usePlaintext()
.keepAliveTime(30, TimeUnit.SECONDS)
.keepAliveTimeout(5, TimeUnit.SECONDS)
.keepAliveWithoutCalls(true)
.build();
FabricGrpc.FabricStub stub = FabricGrpc.newStub(channel);
Metadata headers = new Metadata();
headers.put(Metadata.Key.of("userId", Metadata.ASCII_STRING_MARSHALLER), identificationInputs[0]);
FabricGrpc.FabricStub stubWithHeaders = MetadataUtils.attachHeaders(stub, headers);
StreamObserver<Envelope> observer = stubWithHeaders.biDiEnvelopeChannel(new StreamObserver<Envelope>() {
@Override
public void onNext(Envelope value) {
System.out.println("Received message =====> " + value + " ******* ");
}
@Override
public void onError(Throwable t) {
System.out.println("error on grpc client: " + t.getMessage());
}
@Override
public void onCompleted() {
}
});
what we need is if the connection is idle for a given time, the server should kill the connection. But I think I am not getting how maxConnectionIdle actually works. My previous thought was a connection is idle from the server's perspective if it does not get any message or ping, but then I read this line in the doc " Idleness duration is defined since the most recent time the number of outstanding RPCs became zero or the connection establishment" which I guess means that not any ongoing RPC calls should be there in order to consider a connection as idle. But since it's a bidirectional RPC call, it will be long-lived obviously.
Right now maxConnectionAge is working fine, but how can we configure idle connection on a server with bidirectional RPC. Meaning if the server does not get a ping or any message in a given time frame, it will consider that connection as idle & will terminate it.