Skip to content

Commit

Permalink
Merge pull request #2100 from murgatroid99/grpc-js_dns_resolver_doubl…
Browse files Browse the repository at this point in the history
…e_call

grpc-js: Fix double resolver calls in DNS resolver
  • Loading branch information
murgatroid99 committed Apr 20, 2022
2 parents 028047f + 964c7a6 commit 0a9cf38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/grpc-js/src/backoff-timeout.ts
Expand Up @@ -100,6 +100,7 @@ export class BackoffTimeout {
}

private runTimer(delay: number) {
clearTimeout(this.timerId);
this.timerId = setTimeout(() => {
this.callback();
this.running = false;
Expand Down
10 changes: 9 additions & 1 deletion packages/grpc-js/src/resolver-dns.ts
Expand Up @@ -158,7 +158,6 @@ class DnsResolver implements Resolver {
if (this.ipResult !== null) {
trace('Returning IP address for target ' + uriToString(this.target));
setImmediate(() => {
this.backoff.reset();
this.listener.onSuccessfulResolution(
this.ipResult!,
null,
Expand All @@ -167,6 +166,8 @@ class DnsResolver implements Resolver {
{}
);
});
this.backoff.stop();
this.backoff.reset();
return;
}
if (this.dnsHostname === null) {
Expand All @@ -178,7 +179,11 @@ class DnsResolver implements Resolver {
metadata: new Metadata(),
});
});
this.stopNextResolutionTimer();
} else {
if (this.pendingLookupPromise !== null) {
return;
}
trace('Looking up DNS hostname ' + this.dnsHostname);
/* We clear out latestLookupResult here to ensure that it contains the
* latest result since the last time we started resolving. That way, the
Expand Down Expand Up @@ -299,6 +304,7 @@ class DnsResolver implements Resolver {
}

private startNextResolutionTimer() {
clearTimeout(this.nextResolutionTimer);
this.nextResolutionTimer = setTimeout(() => {
this.stopNextResolutionTimer();
if (this.continueResolving) {
Expand All @@ -314,10 +320,12 @@ class DnsResolver implements Resolver {
}

private startResolutionWithBackoff() {
if (this.pendingLookupPromise === null) {
this.continueResolving = false;
this.startResolution();
this.backoff.runOnce();
this.startNextResolutionTimer();
}
}

updateResolution() {
Expand Down

0 comments on commit 0a9cf38

Please sign in to comment.