Skip to content

Commit

Permalink
internal/balancergroup: eliminate race in exitIdle
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars committed Dec 2, 2021
1 parent 58beff1 commit 3586c4a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/balancergroup/balancergroup.go
Expand Up @@ -110,11 +110,7 @@ func (sbc *subBalancerWrapper) exitIdle() {
ei.ExitIdle()
return
}
for sc, b := range sbc.group.scToSubBalancer {
if b == sbc {
sc.Connect()
}
}
sbc.group.connect(sbc)
}

func (sbc *subBalancerWrapper) updateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
Expand Down Expand Up @@ -383,6 +379,17 @@ func (bg *BalancerGroup) cleanupSubConns(config *subBalancerWrapper) {
bg.incomingMu.Unlock()
}

// connect attempts to connect to all subConns belonging to sb.
func (bg *BalancerGroup) connect(sb *subBalancerWrapper) {
bg.incomingMu.Lock()
for sc, b := range bg.scToSubBalancer {
if b == sb {
sc.Connect()
}
}
bg.incomingMu.Unlock()
}

// Following are actions from the parent grpc.ClientConn, forward to sub-balancers.

// UpdateSubConnState handles the state for the subconn. It finds the
Expand Down

0 comments on commit 3586c4a

Please sign in to comment.