grpc-js: Don't repeat fixed resolver results

This commit is contained in:
Michael Lumish 2023-10-30 09:42:29 -07:00
parent b75a8c98d7
commit 9050ea9dae
4 changed files with 35 additions and 26 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.9.8",
"version": "1.9.9",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

View File

@ -99,6 +99,7 @@ class DnsResolver implements Resolver {
private nextResolutionTimer: NodeJS.Timeout;
private isNextResolutionTimerRunning = false;
private isServiceConfigEnabled = true;
private returnedIpResult = false;
constructor(
private target: GrpcUri,
private listener: ResolverListener,
@ -163,16 +164,19 @@ class DnsResolver implements Resolver {
*/
private startResolution() {
if (this.ipResult !== null) {
trace('Returning IP address for target ' + uriToString(this.target));
setImmediate(() => {
this.listener.onSuccessfulResolution(
this.ipResult!,
null,
null,
null,
{}
);
});
if (!this.returnedIpResult) {
trace('Returning IP address for target ' + uriToString(this.target));
setImmediate(() => {
this.listener.onSuccessfulResolution(
this.ipResult!,
null,
null,
null,
{}
);
});
this.returnedIpResult = true;
}
this.backoff.stop();
this.backoff.reset();
this.stopNextResolutionTimer();
@ -380,6 +384,7 @@ class DnsResolver implements Resolver {
this.latestLookupResult = null;
this.latestServiceConfig = null;
this.latestServiceConfigError = null;
this.returnedIpResult = false;
}
/**

View File

@ -41,6 +41,7 @@ const DEFAULT_PORT = 443;
class IpResolver implements Resolver {
private addresses: SubchannelAddress[] = [];
private error: StatusObject | null = null;
private hasReturnedResult = false;
constructor(
target: GrpcUri,
private listener: ResolverListener,
@ -87,22 +88,25 @@ class IpResolver implements Resolver {
trace('Parsed ' + target.scheme + ' address list ' + this.addresses);
}
updateResolution(): void {
process.nextTick(() => {
if (this.error) {
this.listener.onError(this.error);
} else {
this.listener.onSuccessfulResolution(
this.addresses,
null,
null,
null,
{}
);
}
});
if (!this.hasReturnedResult) {
this.hasReturnedResult = true;
process.nextTick(() => {
if (this.error) {
this.listener.onError(this.error);
} else {
this.listener.onSuccessfulResolution(
this.addresses,
null,
null,
null,
{}
);
}
});
}
}
destroy(): void {
// This resolver owns no resources, so we do nothing here.
this.hasReturnedResult = false;
}
static getDefaultAuthority(target: GrpcUri): string {

View File

@ -97,7 +97,7 @@ describe('Shuffler', () => {
});
});
describe.only('pick_first load balancing policy', () => {
describe('pick_first load balancing policy', () => {
const config = new PickFirstLoadBalancingConfig(false);
let subchannels: MockSubchannel[] = [];
const baseChannelControlHelper: ChannelControlHelper = {