Merge pull request #2904 from murgatroid99/grpc-js-xds_ring_hash_proactive_connect_fix

grpc-js-xds: ring_hash: proactively connect in more cases
This commit is contained in:
Michael Lumish 2025-02-19 09:10:34 -08:00 committed by GitHub
commit 0c093b0b7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 19 deletions

View File

@ -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;
@ -432,6 +434,7 @@ class RingHashLoadBalancer implements LoadBalancer {
this.constructRing(dedupedEndpointList, lbConfig, ringHashSizeCap);
this.updatesPaused = false;
this.calculateAndUpdateState();
this.maybeProactivelyConnect();
});
}
exitIdle(): void {