getState(true) is not moving the channel out of GRPC_CHANNEL_IDLE state.

73 views
Skip to first unread message

Haripriya

unread,
Oct 21, 2019, 3:36:56 AM10/21/19
to grpc.io
Hi,



All gRPC libraries will expose a channel-level API method to poll the current state of a channel. In C++, this method is called GetState and returns an enum for one of the five legal states. It also accepts a boolean try_to_connect to transition to CONNECTING if the channel is currently IDLE. The boolean should act as if an RPC occurred, so it should also reset IDLE_TIMEOUT.

grpc_connectivity_state GetState(bool try_to_connect);


However, even after calling multiple times getState(true) does not move the GRPC channel state from GRPC_CHANNEL_IDLE to GRPC_CHANNEL_READY state.
Also how to simulate this behavior? (i.e Changing the GRPC channel state for debugging purpose)

I would appreciate it if anyone could help me out in this regard.

Thank you in advance.
Regards,
Haripriya

Yash Tibrewal

unread,
Oct 24, 2019, 9:39:25 PM10/24/19
to grpc.io
Hi,

You would need to call WaitForStateChange to wait for the connectivity state to actually change. A sample way to do this would be -

while ((state = channel->GetState(/*try_to_connect=*/true)) != GRPC_CHANNEL_READY) { 
  if (!channel->WaitForStateChange(state, deadline)) {
    // deadline has expired
Message has been deleted

Haripriya

unread,
Oct 24, 2019, 11:17:31 PM10/24/19
to grpc.io
Hi Yash,

Thank you for replying.
Note -  Intermittently I do observe this behavior.  

Yes, "WaitForStateChange" is already been added but still, it does not move to READY state..

   bool connect = true;
   grpc_connectivity_state channel_state = grpcChannel->GetState(connect);
   const int trySeconds = 10;
   const int tryInterval = 1;
   int tryCnt = 0;
   while (channel_state != GRPC_CHANNEL_READY) {
      grpcChannel->WaitForStateChange(channel_state, std::chrono::system_clock::now() + std::chrono::seconds(tryInterval)); 
      channel_state = grpcChannel->GetState(connect);
       if (++tryCnt > (trySeconds / tryInterval)) {
         break;
      }
   }

Also  as per the GRPC doc:

getState()  --- "It also accepts a boolean try_to_connect to transition to CONNECTING if the channel is currently IDLE.
                        The boolean should act as if an RPC occurred" ===>  Does this mean it will trigger  RPC?

How getState(true) is different/equivalent with the normal RPC call ?
Would sending the actual  RPC call would help in moving the channel state from IDLE to READY?


Thank you in advance.

-Regards,
Haripriya 

Yash Tibrewal

unread,
Oct 25, 2019, 3:26:48 PM10/25/19
to grpc.io
I would suggest increasing the interval from 1 second to 20 or 30 seconds. (gRPC uses a default connect deadline of 20 seconds.)
getState(true) is different from actually sending an RPC. getState(true) would simply cause the channel to start connecting. It does NOT send out an RPC.

As a side note, if an RPC is sent while the channel is in the IDLE state, it would trigger channel connection and perform the RPC when the channel is connected.
Reply all
Reply to author
Forward
0 new messages