diff --git a/balancer_conn_wrappers.go b/balancer_conn_wrappers.go index 338d106098fb..b1c910f70b36 100644 --- a/balancer_conn_wrappers.go +++ b/balancer_conn_wrappers.go @@ -226,11 +226,9 @@ func (ccb *ccBalancerWrapper) closeBalancer(m ccbMode) { } ccb.mu.Unlock() - // Give enqueued callbacks a chance to finish. + // Give enqueued callbacks a chance to finish before closing the balancer. <-done - // Spawn a goroutine to close the balancer (since it may block trying to - // cleanup all allocated resources) and return early. - go b.Close() + b.Close() } // exitIdleMode is invoked by grpc when the channel exits idle mode either diff --git a/test/idleness_test.go b/test/idleness_test.go index b7e7ea6cd7cf..78f19edceb31 100644 --- a/test/idleness_test.go +++ b/test/idleness_test.go @@ -408,17 +408,20 @@ func (s) TestChannelIdleness_Enabled_IdleTimeoutRacesWithRPCs(t *testing.T) { // Verify that the ClientConn moves to READY. ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) defer cancel() - awaitState(ctx, t, cc, connectivity.Ready) + client := testgrpc.NewTestServiceClient(cc) + if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err != nil { + t.Errorf("EmptyCall RPC failed: %v", err) + } // Make an RPC every defaultTestShortTimeout duration so as to race with the // idle timeout. Whether the idle timeout wins the race or the RPC wins the // race, RPCs must succeed. - client := testgrpc.NewTestServiceClient(cc) for i := 0; i < 20; i++ { <-time.After(defaultTestShortTimeout) if _, err := client.EmptyCall(ctx, &testpb.Empty{}); err != nil { - t.Errorf("EmptyCall RPC failed: %v", err) + t.Fatalf("EmptyCall RPC failed: %v", err) } + t.Logf("Iteration %d succeeded", i) } }