@@ -186,6 +186,8 @@ export class PickFirstLoadBalancer implements LoadBalancer {
186
186
*/
187
187
private lastError : string | null = null ;
188
188
189
+ private latestAddressList : SubchannelAddress [ ] | null = null ;
190
+
189
191
/**
190
192
* Load balancer that attempts to connect to each backend in the address list
191
193
* in order, and picks the first one that connects, using it for every
@@ -404,19 +406,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
404
406
this . requestedResolutionSinceLastUpdate = false ;
405
407
}
406
408
407
- updateAddressList (
408
- addressList : SubchannelAddress [ ] ,
409
- lbConfig : LoadBalancingConfig
410
- ) : void {
411
- if ( ! ( lbConfig instanceof PickFirstLoadBalancingConfig ) ) {
412
- return ;
413
- }
414
- /* Previously, an update would be discarded if it was identical to the
415
- * previous update, to minimize churn. Now the DNS resolver is
416
- * rate-limited, so that is less of a concern. */
417
- if ( lbConfig . getShuffleAddressList ( ) ) {
418
- addressList = shuffled ( addressList ) ;
419
- }
409
+ private connectToAddressList ( addressList : SubchannelAddress [ ] ) {
420
410
const newChildrenList = addressList . map ( address => ( {
421
411
subchannel : this . channelControlHelper . createSubchannel ( address , { } ) ,
422
412
hasReportedTransientFailure : false ,
@@ -449,10 +439,27 @@ export class PickFirstLoadBalancer implements LoadBalancer {
449
439
this . calculateAndReportNewState ( ) ;
450
440
}
451
441
442
+ updateAddressList (
443
+ addressList : SubchannelAddress [ ] ,
444
+ lbConfig : LoadBalancingConfig
445
+ ) : void {
446
+ if ( ! ( lbConfig instanceof PickFirstLoadBalancingConfig ) ) {
447
+ return ;
448
+ }
449
+ /* Previously, an update would be discarded if it was identical to the
450
+ * previous update, to minimize churn. Now the DNS resolver is
451
+ * rate-limited, so that is less of a concern. */
452
+ if ( lbConfig . getShuffleAddressList ( ) ) {
453
+ addressList = shuffled ( addressList ) ;
454
+ }
455
+ this . latestAddressList = addressList ;
456
+ this . connectToAddressList ( addressList ) ;
457
+ }
458
+
452
459
exitIdle ( ) {
453
- /* The pick_first LB policy is only in the IDLE state if it has no
454
- * addresses to try to connect to and it has no picked subchannel.
455
- * In that case, there is no meaningful action that can be taken here. */
460
+ if ( this . currentState === ConnectivityState . IDLE && this . latestAddressList ) {
461
+ this . connectToAddressList ( this . latestAddressList ) ;
462
+ }
456
463
}
457
464
458
465
resetBackoff ( ) {
0 commit comments