@@ -133,8 +133,9 @@ interface UnderlyingCall {
133
133
* transparent retry attempts may still be sent
134
134
* COMMITTED: One attempt is committed, and no new attempts will be
135
135
* sent
136
+ * NO_RETRY: Retries are disabled. Exists to track the transition to COMMITTED
136
137
*/
137
- type RetryingCallState = 'RETRY' | 'HEDGING' | 'TRANSPARENT_ONLY' | 'COMMITTED' ;
138
+ type RetryingCallState = 'RETRY' | 'HEDGING' | 'TRANSPARENT_ONLY' | 'COMMITTED' | 'NO_RETRY' ;
138
139
139
140
/**
140
141
* The different types of objects that can be stored in the write buffer, with
@@ -229,6 +230,9 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
229
230
} else if ( callConfig . methodConfig . hedgingPolicy ) {
230
231
this . state = 'HEDGING' ;
231
232
this . maxAttempts = Math . min ( callConfig . methodConfig . hedgingPolicy . maxAttempts , maxAttemptsLimit ) ;
233
+ } else if ( channel . getOptions ( ) [ 'grpc.enable_retries' ] === 0 ) {
234
+ this . state = 'NO_RETRY' ;
235
+ this . maxAttempts = 1 ;
232
236
} else {
233
237
this . state = 'TRANSPARENT_ONLY' ;
234
238
this . maxAttempts = 1 ;
@@ -318,8 +322,15 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
318
322
if ( this . state !== 'COMMITTED' ) {
319
323
return ;
320
324
}
321
- const earliestNeededMessageIndex =
322
- this . underlyingCalls [ this . committedCallIndex ! ] . nextMessageToSend ;
325
+ let earliestNeededMessageIndex : number ;
326
+ if ( this . underlyingCalls [ this . committedCallIndex ! ] . state === 'COMPLETED' ) {
327
+ /* If the committed call is completed, clear all messages, even if some
328
+ * have not been sent. */
329
+ earliestNeededMessageIndex = this . getNextBufferIndex ( ) ;
330
+ } else {
331
+ earliestNeededMessageIndex =
332
+ this . underlyingCalls [ this . committedCallIndex ! ] . nextMessageToSend ;
333
+ }
323
334
for (
324
335
let messageIndex = this . writeBufferOffset ;
325
336
messageIndex < earliestNeededMessageIndex ;
@@ -343,16 +354,14 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
343
354
if ( this . state === 'COMMITTED' ) {
344
355
return ;
345
356
}
346
- if ( this . underlyingCalls [ index ] . state === 'COMPLETED' ) {
347
- return ;
348
- }
349
357
this . trace (
350
358
'Committing call [' +
351
359
this . underlyingCalls [ index ] . call . getCallNumber ( ) +
352
360
'] at index ' +
353
361
index
354
362
) ;
355
363
this . state = 'COMMITTED' ;
364
+ this . callConfig . onCommitted ?.( ) ;
356
365
this . committedCallIndex = index ;
357
366
for ( let i = 0 ; i < this . underlyingCalls . length ; i ++ ) {
358
367
if ( i === index ) {
@@ -471,6 +480,7 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
471
480
) {
472
481
switch ( this . state ) {
473
482
case 'COMMITTED' :
483
+ case 'NO_RETRY' :
474
484
case 'TRANSPARENT_ONLY' :
475
485
this . commitCall ( callIndex ) ;
476
486
this . reportStatus ( status ) ;
@@ -566,6 +576,11 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
566
576
this . reportStatus ( status ) ;
567
577
return ;
568
578
}
579
+ if ( this . state === 'NO_RETRY' ) {
580
+ this . commitCall ( callIndex ) ;
581
+ this . reportStatus ( status ) ;
582
+ return ;
583
+ }
569
584
if ( this . state === 'COMMITTED' ) {
570
585
this . reportStatus ( status ) ;
571
586
return ;
0 commit comments