Skip to content

Commit

Permalink
Add logging for DNS update delays due to rate limit or backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Sep 13, 2023
1 parent f1f8d1b commit 10c4bbd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/grpc-js/src/backoff-timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export class BackoffTimeout {
* running is true.
*/
private startTime: Date = new Date();
/**
* The approximate time that the currently running timer will end. Only valid
* if running is true.
*/
private endTime: Date = new Date();

constructor(private callback: () => void, options?: BackoffOptions) {
if (options) {
Expand All @@ -100,6 +105,8 @@ export class BackoffTimeout {
}

private runTimer(delay: number) {
this.endTime = this.startTime;
this.endTime.setMilliseconds(this.endTime.getMilliseconds() + this.nextDelay);
clearTimeout(this.timerId);
this.timerId = setTimeout(() => {
this.callback();
Expand Down Expand Up @@ -178,4 +185,12 @@ export class BackoffTimeout {
this.hasRef = false;
this.timerId.unref?.();
}

/**
* Get the approximate timestamp of when the timer will fire. Only valid if
* this.isRunning() is true.
*/
getEndTime() {
return this.endTime;
}
}
5 changes: 5 additions & 0 deletions packages/grpc-js/src/resolver-dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ class DnsResolver implements Resolver {
* fires. Otherwise, start resolving immediately. */
if (this.pendingLookupPromise === null) {
if (this.isNextResolutionTimerRunning || this.backoff.isRunning()) {
if (this.isNextResolutionTimerRunning) {
trace('resolution update delayed by "min time between resolutions" rate limit');
} else {
trace('resolution update delayed by backoff timer until ' + this.backoff.getEndTime().toISOString());
}
this.continueResolving = true;
} else {
this.startResolutionWithBackoff();
Expand Down
1 change: 1 addition & 0 deletions packages/grpc-js/src/resolving-load-balancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class ResolvingLoadBalancer implements LoadBalancer {
* In that case, the backoff timer callback will call
* updateResolution */
if (this.backoffTimeout.isRunning()) {
trace('requestReresolution delayed by backoff timer until ' + this.backoffTimeout.getEndTime().toISOString());
this.continueResolving = true;
} else {
this.updateResolution();
Expand Down

0 comments on commit 10c4bbd

Please sign in to comment.