mirror of https://github.com/grpc/grpc-node.git
Limit maxAttempts to 5 for retries and hedging
This commit is contained in:
parent
f1f351f3cd
commit
fa21e13ef3
|
@ -296,7 +296,7 @@ export class RetryingCall implements Call {
|
|||
return;
|
||||
}
|
||||
const retryPolicy = this.callConfig!.methodConfig.retryPolicy!;
|
||||
if (this.attempts >= retryPolicy.maxAttempts) {
|
||||
if (this.attempts >= Math.min(retryPolicy.maxAttempts, 5)) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
@ -446,7 +446,7 @@ export class RetryingCall implements Call {
|
|||
return;
|
||||
}
|
||||
const hedgingPolicy = this.callConfig.methodConfig.hedgingPolicy;
|
||||
if (this.attempts >= hedgingPolicy.maxAttempts) {
|
||||
if (this.attempts >= Math.min(hedgingPolicy.maxAttempts, 5)) {
|
||||
return;
|
||||
}
|
||||
this.attempts += 1;
|
||||
|
@ -465,7 +465,7 @@ export class RetryingCall implements Call {
|
|||
return;
|
||||
}
|
||||
const hedgingPolicy = this.callConfig.methodConfig.hedgingPolicy;
|
||||
if (this.attempts >= hedgingPolicy.maxAttempts) {
|
||||
if (this.attempts >= Math.min(hedgingPolicy.maxAttempts, 5)) {
|
||||
return;
|
||||
}
|
||||
const hedgingDelayString = hedgingPolicy.hedgingDelay ?? '0s';
|
||||
|
|
|
@ -216,6 +216,39 @@ describe('Retries', () => {
|
|||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Should not be able to make more than 5 attempts', (done) => {
|
||||
const serviceConfig = {
|
||||
loadBalancingConfig: [],
|
||||
methodConfig: [
|
||||
{
|
||||
name: [{
|
||||
service: 'EchoService'
|
||||
}],
|
||||
retryPolicy: {
|
||||
maxAttempts: 10,
|
||||
initialBackoff: '0.1s',
|
||||
maxBackoff: '10s',
|
||||
backoffMultiplier: 1.2,
|
||||
retryableStatusCodes: [14, 'RESOURCE_EXHAUSTED']
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
const client2 = new EchoService(`localhost:${port}`, grpc.credentials.createInsecure(), {'grpc.service_config': JSON.stringify(serviceConfig)});
|
||||
const metadata = new grpc.Metadata();
|
||||
metadata.set('succeed-on-retry-attempt', '6');
|
||||
metadata.set('respond-with-status', `${grpc.status.RESOURCE_EXHAUSTED}`);
|
||||
client2.echo(
|
||||
{ value: 'test value', value2: 3 },
|
||||
metadata,
|
||||
(error: grpc.ServiceError, response: any) => {
|
||||
assert(error);
|
||||
assert.strictEqual(error.details, 'Failed on retry 4');
|
||||
done();
|
||||
}
|
||||
);
|
||||
})
|
||||
});
|
||||
|
||||
describe('Client with hedging configured', () => {
|
||||
|
@ -297,5 +330,35 @@ describe('Retries', () => {
|
|||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('Should not be able to make more than 5 attempts', (done) => {
|
||||
const serviceConfig = {
|
||||
loadBalancingConfig: [],
|
||||
methodConfig: [
|
||||
{
|
||||
name: [{
|
||||
service: 'EchoService'
|
||||
}],
|
||||
hedgingPolicy: {
|
||||
maxAttempts: 10,
|
||||
nonFatalStatusCodes: [14, 'RESOURCE_EXHAUSTED']
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
const client2 = new EchoService(`localhost:${port}`, grpc.credentials.createInsecure(), {'grpc.service_config': JSON.stringify(serviceConfig)});
|
||||
const metadata = new grpc.Metadata();
|
||||
metadata.set('succeed-on-retry-attempt', '6');
|
||||
metadata.set('respond-with-status', `${grpc.status.RESOURCE_EXHAUSTED}`);
|
||||
client2.echo(
|
||||
{ value: 'test value', value2: 3 },
|
||||
metadata,
|
||||
(error: grpc.ServiceError, response: any) => {
|
||||
assert(error);
|
||||
assert(error.details.startsWith('Failed on retry'));
|
||||
done();
|
||||
}
|
||||
);
|
||||
})
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue