Skip to content

Commit

Permalink
Merge pull request #2904 from murgatroid99/grpc-js-xds_ring_hash_proa…
Browse files Browse the repository at this point in the history
…ctive_connect_fix

grpc-js-xds: ring_hash: proactively connect in more cases
  • Loading branch information
murgatroid99 authored Feb 19, 2025
2 parents 613c832 + da5cca4 commit 0c093b0
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions packages/grpc-js-xds/src/load-balancer-ring-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,30 +235,32 @@ class RingHashLoadBalancer implements LoadBalancer {
this.latestErrorMessage = errorMessage;
}
this.calculateAndUpdateState();
/* If this LB policy is in the TRANSIENT_FAILURE state, requests will
* not trigger new connections, so we need to explicitly try connecting
* to other endpoints that are currently IDLE to try to eventually
* connect to something. */
if (
state === connectivityState.TRANSIENT_FAILURE &&
this.currentState === connectivityState.TRANSIENT_FAILURE
) {
for (const leaf of this.leafMap.values()) {
const leafState = leaf.getConnectivityState();
if (leafState === connectivityState.CONNECTING) {
break;
}
if (leafState === connectivityState.IDLE) {
leaf.startConnecting();
break;
}
}
}
this.maybeProactivelyConnect();
},
}
);
}

private maybeProactivelyConnect() {
/* If this LB policy is in the TRANSIENT_FAILURE or CONNECTING state,
* requests will not trigger new connections, so we need to explicitly try
* connecting to other endpoints that are currently IDLE to try to
* eventually connect to something. */
if (!(this.currentState === connectivityState.TRANSIENT_FAILURE || this.currentState === connectivityState.CONNECTING)) {
return;
}
for (const leaf of this.leafMap.values()) {
const leafState = leaf.getConnectivityState();
if (leafState === connectivityState.CONNECTING) {
break;
}
if (leafState === connectivityState.IDLE) {
leaf.startConnecting();
break;
}
}
}

private calculateAndUpdateState() {
if (this.updatesPaused) {
return;
Expand Down Expand Up @@ -432,6 +434,7 @@ class RingHashLoadBalancer implements LoadBalancer {
this.constructRing(dedupedEndpointList, lbConfig, ringHashSizeCap);
this.updatesPaused = false;
this.calculateAndUpdateState();
this.maybeProactivelyConnect();
});
}
exitIdle(): void {
Expand Down

0 comments on commit 0c093b0

Please sign in to comment.