Skip to content

Commit

Permalink
grpclb: consider IDLE SubConns as connecting (grpc#4031)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
menghanl authored and davidkhala committed Dec 7, 2020
1 parent 6189a9a commit d94d192
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions balancer/grpclb/grpclb.go
Expand Up @@ -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
Expand All @@ -298,7 +302,7 @@ func (lb *lbBalancer) aggregateSubConnStates() connectivity.State {
switch state {
case connectivity.Ready:
return connectivity.Ready
case connectivity.Connecting:
case connectivity.Connecting, connectivity.Idle:
numConnecting++
}
}
Expand Down
2 changes: 1 addition & 1 deletion balancer/grpclb/grpclb_test.go
Expand Up @@ -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 _, <nil>", testC, err)
}
}
Expand Down

0 comments on commit d94d192

Please sign in to comment.