Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/grpc-js/src/retrying-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export class RetryThrottler {
}

addCallSucceeded() {
this.tokens = Math.max(this.tokens + this.tokenRatio, this.maxTokens);
this.tokens = Math.min(this.tokens + this.tokenRatio, this.maxTokens);
}

addCallFailed() {
this.tokens = Math.min(this.tokens - 1, 0);
this.tokens = Math.max(this.tokens - 1, 0);
}

canRetryCall() {
return this.tokens > this.maxTokens / 2;
return this.tokens > (this.maxTokens / 2);
}
}

Expand Down Expand Up @@ -217,7 +217,10 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
private readonly retryThrottler?: RetryThrottler
) {
const maxAttemptsLimit = channel.getOptions()['grpc-node.retry_max_attempts_limit'] ?? DEFAULT_MAX_ATTEMPTS_LIMIT;
if (callConfig.methodConfig.retryPolicy) {
if (channel.getOptions()['grpc.enable_retries'] === 0) {
this.state = 'NO_RETRY';
this.maxAttempts = 1;
} else if (callConfig.methodConfig.retryPolicy) {
this.state = 'RETRY';
const retryPolicy = callConfig.methodConfig.retryPolicy;
this.nextRetryBackoffSec = this.initialRetryBackoffSec = Number(
Expand All @@ -230,9 +233,6 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
} else if (callConfig.methodConfig.hedgingPolicy) {
this.state = 'HEDGING';
this.maxAttempts = Math.min(callConfig.methodConfig.hedgingPolicy.maxAttempts, maxAttemptsLimit);
} else if (channel.getOptions()['grpc.enable_retries'] === 0) {
this.state = 'NO_RETRY';
this.maxAttempts = 1;
} else {
this.state = 'TRANSPARENT_ONLY';
this.maxAttempts = 1;
Expand Down Expand Up @@ -459,6 +459,9 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
callback(true);
this.attempts += 1;
this.startNewAttempt();
} else {
this.trace('Retry attempt denied by throttling policy');
callback(false);
}
}, retryDelayMs);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/grpc-js/test/test-retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ describe('Retries', () => {
},
},
],
retryThrottling: {
maxTokens: 1000,
tokenRatio: 0.1,
},
};
client = new EchoService(
`localhost:${port}`,
Expand Down