[grpc-core] How grpc channel retry the connection?

2,876 views
Skip to first unread message

yihao yang

unread,
Sep 12, 2017, 10:26:05 PM9/12/17
to grpc.io
Hi, all

I know some basics about how completion queue work. But I do not know how channel reconnection work. Can anyone describe some detail about how to trigger a channel reconnection in the code level?

Thanks,
Yihao

Eric Anderson

unread,
Sep 19, 2017, 8:05:20 PM9/19/17
to yihao yang, grpc.io
You shouldn't need to do anything. The channel will automatically attempt to reconnect on later RPCs. If connecting fails, it will use exponential backoff.

When you initially create the channel, it doesn't eagerly create a connection. It is only after requesting RPCs that it makes a connection. So it's already quite normal for it to make connections on-demand.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/19d4f65a-8a24-4905-9f47-2d30be5207c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yihao yang

unread,
Sep 21, 2017, 2:09:49 PM9/21/17
to grpc.io
Hi, Eric

I guess the default wait_for_ready option is just to wait the exponential backoff reconnect until it timeouts and will not issue the channel reconnect immediately. Am I right?

Thanks,
Yihao

在 2017年9月19日星期二 UTC-7下午5:05:20,Eric Anderson写道:
You shouldn't need to do anything. The channel will automatically attempt to reconnect on later RPCs. If connecting fails, it will use exponential backoff.

When you initially create the channel, it doesn't eagerly create a connection. It is only after requesting RPCs that it makes a connection. So it's already quite normal for it to make connections on-demand.
On Tue, Sep 12, 2017 at 7:26 PM, yihao yang <yangyi...@gmail.com> wrote:
Hi, all

I know some basics about how completion queue work. But I do not know how channel reconnection work. Can anyone describe some detail about how to trigger a channel reconnection in the code level?

Thanks,
Yihao

--
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+u...@googlegroups.com.

yihao yang

unread,
Sep 21, 2017, 2:11:12 PM9/21/17
to grpc.io
BTW, I just curious about the implementation of the channel reconnect. And I cannot find any docs about it.

在 2017年9月21日星期四 UTC-7上午11:09:49,yihao yang写道:

Eric Anderson

unread,
Sep 21, 2017, 2:31:03 PM9/21/17
to yihao yang, grpc.io
在 2017年9月21日星期四 UTC-7上午11:09:49,yihao yang写道:
I guess the default wait_for_ready option is just to wait the exponential backoff reconnect until it timeouts and will not issue the channel reconnect immediately. Am I right?

Yes, the wait_for_ready says you'd rather wait than get a failed RPC. So it does not fail the RPC if the connection is known-bad (which is when we're in exponential backoff). It waits until either 1) a connection is established or 2) the RPC's deadline is exceeded.

On Thu, Sep 21, 2017 at 11:11 AM, yihao yang <yangyi...@gmail.com> wrote:
BTW, I just curious about the implementation of the channel reconnect. And I cannot find any docs about it.

 It is defined in doc/connection-backoff.md.

yihao yang

unread,
Sep 29, 2017, 3:15:56 PM9/29/17
to grpc.io

Hi, Eric 

 It is defined in doc/connection-backoff.md.
Actually, I'm curious how the specification is integrated into the CQ logic.
For the auto reconnection, my concern is if I want to implement my own retry logic, since the reconnection is actually controlled in the background thread which poll the cq. The user retry logic sometimes are not working, since grpc cannot make sure every time user retry a rpc will auto reconnect the channel (e.g. at the retry time, the channel state is also TRANS_FAILURE). 

Thanks,
Yihao

在 2017年9月21日星期四 UTC-7上午11:31:03,Eric Anderson写道:

tanbo yi

unread,
Jul 30, 2021, 12:50:14 AM7/30/21
to grpc.io
HI I meet the same issue, what's your sulition?
Reply all
Reply to author
Forward
0 new messages