Skip to content

Commit 0c093b0

Browse files
authored
Merge pull request #2904 from murgatroid99/grpc-js-xds_ring_hash_proactive_connect_fix
grpc-js-xds: ring_hash: proactively connect in more cases
2 parents 613c832 + da5cca4 commit 0c093b0

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

packages/grpc-js-xds/src/load-balancer-ring-hash.ts

+22-19
Original file line numberDiff line numberDiff line change
@@ -235,30 +235,32 @@ class RingHashLoadBalancer implements LoadBalancer {
235235
this.latestErrorMessage = errorMessage;
236236
}
237237
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();
257239
},
258240
}
259241
);
260242
}
261243

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+
262264
private calculateAndUpdateState() {
263265
if (this.updatesPaused) {
264266
return;
@@ -432,6 +434,7 @@ class RingHashLoadBalancer implements LoadBalancer {
432434
this.constructRing(dedupedEndpointList, lbConfig, ringHashSizeCap);
433435
this.updatesPaused = false;
434436
this.calculateAndUpdateState();
437+
this.maybeProactivelyConnect();
435438
});
436439
}
437440
exitIdle(): void {

0 commit comments

Comments
 (0)