@@ -278,15 +278,24 @@ export class RetryingCall implements Call {
278278 }
279279
280280 private commitCallWithMostMessages ( ) {
281+ if ( this . state === 'COMMITTED' ) {
282+ return ;
283+ }
281284 let mostMessages = - 1 ;
282285 let callWithMostMessages = - 1 ;
283286 for ( const [ index , childCall ] of this . underlyingCalls . entries ( ) ) {
284- if ( childCall . nextMessageToSend > mostMessages ) {
287+ if ( childCall . state === 'ACTIVE' && childCall . nextMessageToSend > mostMessages ) {
285288 mostMessages = childCall . nextMessageToSend ;
286289 callWithMostMessages = index ;
287290 }
288291 }
289- this . commitCall ( callWithMostMessages ) ;
292+ if ( callWithMostMessages === - 1 ) {
293+ /* There are no active calls, disable retries to force the next call that
294+ * is started to be committed. */
295+ this . state = 'TRANSPARENT_ONLY' ;
296+ } else {
297+ this . commitCall ( callWithMostMessages ) ;
298+ }
290299 }
291300
292301 private isStatusCodeInList ( list : ( Status | string ) [ ] , code : Status ) {
@@ -606,7 +615,11 @@ export class RetryingCall implements Call {
606615 }
607616 } else {
608617 this . commitCallWithMostMessages ( ) ;
609- const call = this . underlyingCalls [ this . committedCallIndex ! ] ;
618+ // commitCallWithMostMessages can fail if we are between ping attempts
619+ if ( this . committedCallIndex === null ) {
620+ return ;
621+ }
622+ const call = this . underlyingCalls [ this . committedCallIndex ] ;
610623 bufferEntry . callback = context . callback ;
611624 if ( call . state === 'ACTIVE' && call . nextMessageToSend === messageIndex ) {
612625 call . call . sendMessageWithContext ( {
0 commit comments