Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc-js: Fix double resolver calls in DNS resolver #2100

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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