@@ -172,6 +172,8 @@ interface WriteBufferEntry {
172
172
173
173
const PREVIONS_RPC_ATTEMPTS_METADATA_KEY = 'grpc-previous-rpc-attempts' ;
174
174
175
+ const DEFAULT_MAX_ATTEMPTS_LIMIT = 5 ;
176
+
175
177
export class RetryingCall implements Call , DeadlineInfoProvider {
176
178
private state : RetryingCallState ;
177
179
private listener : InterceptingListener | null = null ;
@@ -201,6 +203,7 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
201
203
private initialRetryBackoffSec = 0 ;
202
204
private nextRetryBackoffSec = 0 ;
203
205
private startTime : Date ;
206
+ private maxAttempts : number ;
204
207
constructor (
205
208
private readonly channel : InternalChannel ,
206
209
private readonly callConfig : CallConfig ,
@@ -212,6 +215,7 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
212
215
private readonly bufferTracker : MessageBufferTracker ,
213
216
private readonly retryThrottler ?: RetryThrottler
214
217
) {
218
+ const maxAttemptsLimit = channel . getOptions ( ) [ 'grpc-node.retry_max_attempts_limit' ] ?? DEFAULT_MAX_ATTEMPTS_LIMIT ;
215
219
if ( callConfig . methodConfig . retryPolicy ) {
216
220
this . state = 'RETRY' ;
217
221
const retryPolicy = callConfig . methodConfig . retryPolicy ;
@@ -221,10 +225,13 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
221
225
retryPolicy . initialBackoff . length - 1
222
226
)
223
227
) ;
228
+ this . maxAttempts = Math . min ( retryPolicy . maxAttempts , maxAttemptsLimit ) ;
224
229
} else if ( callConfig . methodConfig . hedgingPolicy ) {
225
230
this . state = 'HEDGING' ;
231
+ this . maxAttempts = Math . min ( callConfig . methodConfig . hedgingPolicy . maxAttempts , maxAttemptsLimit ) ;
226
232
} else {
227
233
this . state = 'TRANSPARENT_ONLY' ;
234
+ this . maxAttempts = 1 ;
228
235
}
229
236
this . startTime = new Date ( ) ;
230
237
}
@@ -419,8 +426,7 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
419
426
callback ( false ) ;
420
427
return ;
421
428
}
422
- const retryPolicy = this . callConfig ! . methodConfig . retryPolicy ! ;
423
- if ( this . attempts >= Math . min ( retryPolicy . maxAttempts , 5 ) ) {
429
+ if ( this . attempts >= this . maxAttempts ) {
424
430
callback ( false ) ;
425
431
return ;
426
432
}
@@ -596,8 +602,7 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
596
602
if ( ! this . callConfig . methodConfig . hedgingPolicy ) {
597
603
return ;
598
604
}
599
- const hedgingPolicy = this . callConfig . methodConfig . hedgingPolicy ;
600
- if ( this . attempts >= Math . min ( hedgingPolicy . maxAttempts , 5 ) ) {
605
+ if ( this . attempts >= this . maxAttempts ) {
601
606
return ;
602
607
}
603
608
this . attempts += 1 ;
@@ -616,7 +621,7 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
616
621
return ;
617
622
}
618
623
const hedgingPolicy = this . callConfig . methodConfig . hedgingPolicy ;
619
- if ( this . attempts >= Math . min ( hedgingPolicy . maxAttempts , 5 ) ) {
624
+ if ( this . attempts >= this . maxAttempts ) {
620
625
return ;
621
626
}
622
627
const hedgingDelayString = hedgingPolicy . hedgingDelay ?? '0s' ;
0 commit comments