Yes, your understanding is correct. If a connection has an active bi-di 
call and even if there is no activity in that call gRPC will keep the 
connection active using PING frames. It is alluded to in this spec 
<https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md#abstract>
 . 
Hope that answers your questions.

On Wednesday, August 30, 2023 at 6:00:55 AM UTC-7 airas yaqub wrote:

> I think current options are only for unary RPC done on a channel, but in 
> the case of bidirectional streaming, we have a channel where a long-lived 
> bidirectional RPC is made & within that RPC connection, we send messages. 
> But these server options do not take account of the stream messages, they 
> only consider RPC calls. correct me guys if I am wrong in my understanding.
>
> On Wednesday, August 30, 2023 at 5:45:11 PM UTC+5 airas yaqub wrote:
>
>> 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.   
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to grpc-io+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/14c0763b-2e1d-4bd7-9132-693d2159a853n%40googlegroups.com.

Reply via email to