@@ -186,6 +186,8 @@ export class PickFirstLoadBalancer implements LoadBalancer {
186186 */
187187 private lastError : string | null = null ;
188188
189+ private latestAddressList : SubchannelAddress [ ] | null = null ;
190+
189191 /**
190192 * Load balancer that attempts to connect to each backend in the address list
191193 * in order, and picks the first one that connects, using it for every
@@ -404,19 +406,7 @@ export class PickFirstLoadBalancer implements LoadBalancer {
404406 this . requestedResolutionSinceLastUpdate = false ;
405407 }
406408
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 [ ] ) {
420410 const newChildrenList = addressList . map ( address => ( {
421411 subchannel : this . channelControlHelper . createSubchannel ( address , { } ) ,
422412 hasReportedTransientFailure : false ,
@@ -449,10 +439,27 @@ export class PickFirstLoadBalancer implements LoadBalancer {
449439 this . calculateAndReportNewState ( ) ;
450440 }
451441
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+
452459 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+ }
456463 }
457464
458465 resetBackoff ( ) {
0 commit comments