From 215d205f832caeaca534cf922faea588372fa3d1 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Wed, 11 Nov 2020 16:26:28 -0800 Subject: [PATCH 1/2] [grpclb_start_connecting] grpclb: consider IDLE SubConns as connecting Otherwise, when the first response is received from the grpclb server, the parent ClientConn enters TransientFailure, and the first several non-wait-for-ready RPCs will fail. --- balancer/grpclb/grpclb.go | 2 +- balancer/grpclb/grpclb_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/balancer/grpclb/grpclb.go b/balancer/grpclb/grpclb.go index a7424cf8d2d..3a95ca4e5a0 100644 --- a/balancer/grpclb/grpclb.go +++ b/balancer/grpclb/grpclb.go @@ -298,7 +298,7 @@ func (lb *lbBalancer) aggregateSubConnStates() connectivity.State { switch state { case connectivity.Ready: return connectivity.Ready - case connectivity.Connecting: + case connectivity.Connecting, connectivity.Idle: numConnecting++ } } diff --git a/balancer/grpclb/grpclb_test.go b/balancer/grpclb/grpclb_test.go index dcc5235703a..dc94ca87784 100644 --- a/balancer/grpclb/grpclb_test.go +++ b/balancer/grpclb/grpclb_test.go @@ -452,7 +452,7 @@ func (s) TestGRPCLB(t *testing.T) { ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - if _, err := testC.EmptyCall(ctx, &testpb.Empty{}, grpc.WaitForReady(true)); err != nil { + if _, err := testC.EmptyCall(ctx, &testpb.Empty{}); err != nil { t.Fatalf("%v.EmptyCall(_, _) = _, %v, want _, ", testC, err) } } From 86764c334f9fbb0e6a933e2d94de75e97681a7d4 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Wed, 11 Nov 2020 17:17:29 -0800 Subject: [PATCH 2/2] [grpclb_start_connecting] c1 --- balancer/grpclb/grpclb.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/balancer/grpclb/grpclb.go b/balancer/grpclb/grpclb.go index 3a95ca4e5a0..a43d8964119 100644 --- a/balancer/grpclb/grpclb.go +++ b/balancer/grpclb/grpclb.go @@ -288,7 +288,11 @@ func (lb *lbBalancer) regeneratePicker(resetDrop bool) { // // The aggregated state is: // - If at least one SubConn in Ready, the aggregated state is Ready; -// - Else if at least one SubConn in Connecting, the aggregated state is Connecting; +// - Else if at least one SubConn in Connecting or IDLE, the aggregated state is Connecting; +// - It's OK to consider IDLE as Connecting. SubConns never stay in IDLE, +// they start to connect immediately. But there's a race between the overall +// state is reported, and when the new SubConn state arrives. And SubConns +// never go back to IDLE. // - Else the aggregated state is TransientFailure. func (lb *lbBalancer) aggregateSubConnStates() connectivity.State { var numConnecting uint64