@@ -211,6 +211,7 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
211211 private nextRetryBackoffSec = 0 ;
212212 private startTime : Date ;
213213 private maxAttempts : number ;
214+ private halfClosed : boolean = false ;
214215 constructor (
215216 private readonly channel : InternalChannel ,
216217 private readonly callConfig : CallConfig ,
@@ -789,8 +790,11 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
789790 ) ;
790791 break ;
791792 case 'HALF_CLOSE' :
792- childCall . nextMessageToSend += 1 ;
793- childCall . call . halfClose ( ) ;
793+ if ( this . halfClosed !== true ) {
794+ childCall . nextMessageToSend += 1 ;
795+ childCall . call . halfClose ( ) ;
796+ this . halfClosed = true ;
797+ }
794798 break ;
795799 case 'FREED' :
796800 // Should not be possible
@@ -868,12 +872,13 @@ export class RetryingCall implements Call, DeadlineInfoProvider {
868872 allocated : false ,
869873 } ) ;
870874 for ( const call of this . underlyingCalls ) {
871- if (
872- call ?. state === 'ACTIVE' &&
873- call . nextMessageToSend === halfCloseIndex
874- ) {
875- call . nextMessageToSend += 1 ;
876- call . call . halfClose ( ) ;
875+ if ( call ?. state === 'ACTIVE' && this . halfClosed !== true ) {
876+ // || call.nextMessageToSend === halfCloseIndex - 1 added to not wait for write callback
877+ if ( call . nextMessageToSend === halfCloseIndex || call . nextMessageToSend === halfCloseIndex - 1 ) {
878+ call . nextMessageToSend += 1 ;
879+ call . call . halfClose ( ) ;
880+ this . halfClosed = true ;
881+ }
877882 }
878883 }
879884 }
0 commit comments