@@ -142,7 +142,6 @@ func (bb) Name() string {
142
142
type scUpdate struct {
143
143
scw * subConnWrapper
144
144
state balancer.SubConnState
145
- cb func (balancer.SubConnState )
146
145
}
147
146
148
147
type ejectionUpdate struct {
@@ -346,7 +345,7 @@ func (b *outlierDetectionBalancer) ResolverError(err error) {
346
345
b .child .ResolverError (err )
347
346
}
348
347
349
- func (b * outlierDetectionBalancer ) updateSubConnState (sc balancer.SubConn , state balancer.SubConnState , cb func (balancer. SubConnState ) ) {
348
+ func (b * outlierDetectionBalancer ) updateSubConnState (sc balancer.SubConn , state balancer.SubConnState ) {
350
349
b .mu .Lock ()
351
350
defer b .mu .Unlock ()
352
351
scw , ok := b .scWrappers [sc ]
@@ -362,12 +361,11 @@ func (b *outlierDetectionBalancer) updateSubConnState(sc balancer.SubConn, state
362
361
b .scUpdateCh .Put (& scUpdate {
363
362
scw : scw ,
364
363
state : state ,
365
- cb : cb ,
366
364
})
367
365
}
368
366
369
367
func (b * outlierDetectionBalancer ) UpdateSubConnState (sc balancer.SubConn , state balancer.SubConnState ) {
370
- b .updateSubConnState ( sc , state , nil )
368
+ b .logger . Errorf ( "UpdateSubConnState(%v, %+v) called unexpectedly" , sc , state )
371
369
}
372
370
373
371
func (b * outlierDetectionBalancer ) Close () {
@@ -474,7 +472,7 @@ func (b *outlierDetectionBalancer) UpdateState(s balancer.State) {
474
472
func (b * outlierDetectionBalancer ) NewSubConn (addrs []resolver.Address , opts balancer.NewSubConnOptions ) (balancer.SubConn , error ) {
475
473
var sc balancer.SubConn
476
474
oldListener := opts .StateListener
477
- opts .StateListener = func (state balancer.SubConnState ) { b .updateSubConnState (sc , state , oldListener ) }
475
+ opts .StateListener = func (state balancer.SubConnState ) { b .updateSubConnState (sc , state ) }
478
476
sc , err := b .cc .NewSubConn (addrs , opts )
479
477
if err != nil {
480
478
return nil , err
@@ -483,6 +481,7 @@ func (b *outlierDetectionBalancer) NewSubConn(addrs []resolver.Address, opts bal
483
481
SubConn : sc ,
484
482
addresses : addrs ,
485
483
scUpdateCh : b .scUpdateCh ,
484
+ listener : oldListener ,
486
485
}
487
486
b .mu .Lock ()
488
487
defer b .mu .Unlock ()
@@ -617,8 +616,8 @@ func (b *outlierDetectionBalancer) handleSubConnUpdate(u *scUpdate) {
617
616
scw .latestState = u .state
618
617
if ! scw .ejected {
619
618
b .childMu .Lock ()
620
- if u . cb != nil {
621
- u . cb (u .state )
619
+ if scw . listener != nil {
620
+ scw . listener (u .state )
622
621
} else {
623
622
b .child .UpdateSubConnState (scw , u .state )
624
623
}
@@ -640,7 +639,11 @@ func (b *outlierDetectionBalancer) handleEjectedUpdate(u *ejectionUpdate) {
640
639
}
641
640
}
642
641
b .childMu .Lock ()
643
- b .child .UpdateSubConnState (scw , stateToUpdate )
642
+ if scw .listener != nil {
643
+ scw .listener (stateToUpdate )
644
+ } else {
645
+ b .child .UpdateSubConnState (scw , stateToUpdate )
646
+ }
644
647
b .childMu .Unlock ()
645
648
}
646
649
0 commit comments