@@ -737,9 +737,24 @@ export class Http2ServerCallStream<
737
737
) {
738
738
const decoder = new StreamDecoder ( ) ;
739
739
740
+ let readsDone = false ;
741
+
742
+ let pendingMessageProcessing = false ;
743
+
744
+ let pushedEnd = false ;
745
+
746
+ const maybePushEnd = ( ) => {
747
+ if ( ! pushedEnd && readsDone && ! pendingMessageProcessing ) {
748
+ pushedEnd = true ;
749
+ this . pushOrBufferMessage ( readable , null ) ;
750
+ }
751
+ }
752
+
740
753
this . stream . on ( 'data' , async ( data : Buffer ) => {
741
754
const messages = decoder . write ( data ) ;
742
755
756
+ pendingMessageProcessing = true ;
757
+ this . stream . pause ( ) ;
743
758
for ( const message of messages ) {
744
759
if (
745
760
this . maxReceiveMessageSize !== - 1 &&
@@ -763,10 +778,14 @@ export class Http2ServerCallStream<
763
778
764
779
this . pushOrBufferMessage ( readable , decompressedMessage ) ;
765
780
}
781
+ pendingMessageProcessing = false ;
782
+ this . stream . resume ( ) ;
783
+ maybePushEnd ( ) ;
766
784
} ) ;
767
785
768
786
this . stream . once ( 'end' , ( ) => {
769
- this . pushOrBufferMessage ( readable , null ) ;
787
+ readsDone = true ;
788
+ maybePushEnd ( ) ;
770
789
} ) ;
771
790
}
772
791
@@ -810,6 +829,7 @@ export class Http2ServerCallStream<
810
829
messageBytes : Buffer | null
811
830
) {
812
831
if ( messageBytes === null ) {
832
+ trace ( 'Received end of stream' ) ;
813
833
if ( this . canPush ) {
814
834
readable . push ( null ) ;
815
835
} else {
@@ -819,6 +839,8 @@ export class Http2ServerCallStream<
819
839
return ;
820
840
}
821
841
842
+ trace ( 'Received message of length ' + messageBytes . length ) ;
843
+
822
844
this . isPushPending = true ;
823
845
824
846
try {
0 commit comments