@@ -273,15 +273,24 @@ export class RetryingCall implements Call {
273273 }
274274
275275 private commitCallWithMostMessages ( ) {
276+ if ( this . state === 'COMMITTED' ) {
277+ return ;
278+ }
276279 let mostMessages = - 1 ;
277280 let callWithMostMessages = - 1 ;
278281 for ( const [ index , childCall ] of this . underlyingCalls . entries ( ) ) {
279- if ( childCall . nextMessageToSend > mostMessages ) {
282+ if ( childCall . state === 'ACTIVE' && childCall . nextMessageToSend > mostMessages ) {
280283 mostMessages = childCall . nextMessageToSend ;
281284 callWithMostMessages = index ;
282285 }
283286 }
284- this . commitCall ( callWithMostMessages ) ;
287+ if ( callWithMostMessages === - 1 ) {
288+ /* There are no active calls, disable retries to force the next call that
289+ * is started to be committed. */
290+ this . state = 'TRANSPARENT_ONLY' ;
291+ } else {
292+ this . commitCall ( callWithMostMessages ) ;
293+ }
285294 }
286295
287296 private isStatusCodeInList ( list : ( Status | string ) [ ] , code : Status ) {
@@ -601,7 +610,11 @@ export class RetryingCall implements Call {
601610 }
602611 } else {
603612 this . commitCallWithMostMessages ( ) ;
604- const call = this . underlyingCalls [ this . committedCallIndex ! ] ;
613+ // commitCallWithMostMessages can fail if we are between ping attempts
614+ if ( this . committedCallIndex === null ) {
615+ return ;
616+ }
617+ const call = this . underlyingCalls [ this . committedCallIndex ] ;
605618 bufferEntry . callback = context . callback ;
606619 if ( call . state === 'ACTIVE' && call . nextMessageToSend === messageIndex ) {
607620 call . call . sendMessageWithContext ( {
0 commit comments