diff --git a/balancer_wrapper.go b/balancer_wrapper.go index 22111f048691..efdbe7cf4fae 100644 --- a/balancer_wrapper.go +++ b/balancer_wrapper.go @@ -262,7 +262,7 @@ type acBalancerWrapper struct { // updateState is invoked by grpc to push a subConn state update to the // underlying balancer. -func (acbw *acBalancerWrapper) updateState(s connectivity.State, curAddr resolver.Address, err error) { +func (acbw *acBalancerWrapper) updateState(s connectivity.State, curAddr resolver.Address, err error, readyChan chan struct{}) { acbw.ccb.serializer.TrySchedule(func(ctx context.Context) { if ctx.Err() != nil || acbw.ccb.balancer == nil { return @@ -278,11 +278,11 @@ func (acbw *acBalancerWrapper) updateState(s connectivity.State, curAddr resolve acbw.ac.mu.Lock() defer acbw.ac.mu.Unlock() if s == connectivity.Ready { - // When changing states to READY, reset stateReadyChan. Wait until + // When changing states to READY, close stateReadyChan. Wait until // after we notify the LB policy's listener(s) in order to prevent // ac.getTransport() from unblocking before the LB policy starts // tracking the subchannel as READY. - close(acbw.ac.stateReadyChan) + close(readyChan) } }) } diff --git a/clientconn.go b/clientconn.go index a3228148d729..a680fefc1385 100644 --- a/clientconn.go +++ b/clientconn.go @@ -1208,7 +1208,7 @@ func (ac *addrConn) updateConnectivityState(s connectivity.State, lastErr error) } else { channelz.Infof(logger, ac.channelz, "Subchannel Connectivity change to %v, last error: %s", s, lastErr) } - ac.acbw.updateState(s, ac.curAddr, lastErr) + ac.acbw.updateState(s, ac.curAddr, lastErr, ac.stateReadyChan) } // adjustParams updates parameters used to create transports upon