Skip to content

Commit 10c4bbd

Browse files
committed
Add logging for DNS update delays due to rate limit or backoff
1 parent f1f8d1b commit 10c4bbd

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

packages/grpc-js/src/backoff-timeout.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export class BackoffTimeout {
7878
* running is true.
7979
*/
8080
private startTime: Date = new Date();
81+
/**
82+
* The approximate time that the currently running timer will end. Only valid
83+
* if running is true.
84+
*/
85+
private endTime: Date = new Date();
8186

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

102107
private runTimer(delay: number) {
108+
this.endTime = this.startTime;
109+
this.endTime.setMilliseconds(this.endTime.getMilliseconds() + this.nextDelay);
103110
clearTimeout(this.timerId);
104111
this.timerId = setTimeout(() => {
105112
this.callback();
@@ -178,4 +185,12 @@ export class BackoffTimeout {
178185
this.hasRef = false;
179186
this.timerId.unref?.();
180187
}
188+
189+
/**
190+
* Get the approximate timestamp of when the timer will fire. Only valid if
191+
* this.isRunning() is true.
192+
*/
193+
getEndTime() {
194+
return this.endTime;
195+
}
181196
}

packages/grpc-js/src/resolver-dns.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ class DnsResolver implements Resolver {
353353
* fires. Otherwise, start resolving immediately. */
354354
if (this.pendingLookupPromise === null) {
355355
if (this.isNextResolutionTimerRunning || this.backoff.isRunning()) {
356+
if (this.isNextResolutionTimerRunning) {
357+
trace('resolution update delayed by "min time between resolutions" rate limit');
358+
} else {
359+
trace('resolution update delayed by backoff timer until ' + this.backoff.getEndTime().toISOString());
360+
}
356361
this.continueResolving = true;
357362
} else {
358363
this.startResolutionWithBackoff();

packages/grpc-js/src/resolving-load-balancer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export class ResolvingLoadBalancer implements LoadBalancer {
222222
* In that case, the backoff timer callback will call
223223
* updateResolution */
224224
if (this.backoffTimeout.isRunning()) {
225+
trace('requestReresolution delayed by backoff timer until ' + this.backoffTimeout.getEndTime().toISOString());
225226
this.continueResolving = true;
226227
} else {
227228
this.updateResolution();

0 commit comments

Comments
 (0)