@@ -235,30 +235,32 @@ class RingHashLoadBalancer implements LoadBalancer {
235
235
this . latestErrorMessage = errorMessage ;
236
236
}
237
237
this . calculateAndUpdateState ( ) ;
238
- /* If this LB policy is in the TRANSIENT_FAILURE state, requests will
239
- * not trigger new connections, so we need to explicitly try connecting
240
- * to other endpoints that are currently IDLE to try to eventually
241
- * connect to something. */
242
- if (
243
- state === connectivityState . TRANSIENT_FAILURE &&
244
- this . currentState === connectivityState . TRANSIENT_FAILURE
245
- ) {
246
- for ( const leaf of this . leafMap . values ( ) ) {
247
- const leafState = leaf . getConnectivityState ( ) ;
248
- if ( leafState === connectivityState . CONNECTING ) {
249
- break ;
250
- }
251
- if ( leafState === connectivityState . IDLE ) {
252
- leaf . startConnecting ( ) ;
253
- break ;
254
- }
255
- }
256
- }
238
+ this . maybeProactivelyConnect ( ) ;
257
239
} ,
258
240
}
259
241
) ;
260
242
}
261
243
244
+ private maybeProactivelyConnect ( ) {
245
+ /* If this LB policy is in the TRANSIENT_FAILURE or CONNECTING state,
246
+ * requests will not trigger new connections, so we need to explicitly try
247
+ * connecting to other endpoints that are currently IDLE to try to
248
+ * eventually connect to something. */
249
+ if ( ! ( this . currentState === connectivityState . TRANSIENT_FAILURE || this . currentState === connectivityState . CONNECTING ) ) {
250
+ return ;
251
+ }
252
+ for ( const leaf of this . leafMap . values ( ) ) {
253
+ const leafState = leaf . getConnectivityState ( ) ;
254
+ if ( leafState === connectivityState . CONNECTING ) {
255
+ break ;
256
+ }
257
+ if ( leafState === connectivityState . IDLE ) {
258
+ leaf . startConnecting ( ) ;
259
+ break ;
260
+ }
261
+ }
262
+ }
263
+
262
264
private calculateAndUpdateState ( ) {
263
265
if ( this . updatesPaused ) {
264
266
return ;
@@ -432,6 +434,7 @@ class RingHashLoadBalancer implements LoadBalancer {
432
434
this . constructRing ( dedupedEndpointList , lbConfig , ringHashSizeCap ) ;
433
435
this . updatesPaused = false ;
434
436
this . calculateAndUpdateState ( ) ;
437
+ this . maybeProactivelyConnect ( ) ;
435
438
} ) ;
436
439
}
437
440
exitIdle ( ) : void {
0 commit comments