Skip to content

Commit bbe4a9d

Browse files
authored
Call Complete on Http2Stream when stream is done earlier (#7933)
1 parent a2c8a34 commit bbe4a9d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,16 @@ public Task OnDataAsync(Http2Frame dataFrame, ReadOnlySequence<byte> payload)
368368
{
369369
RequestBodyPipe.Writer.Write(segment.Span);
370370
}
371-
var flushTask = RequestBodyPipe.Writer.FlushAsync();
372371

373-
// It shouldn't be possible for the RequestBodyPipe to fill up an return an incomplete task if
374-
// _inputFlowControl.Advance() didn't throw.
375-
Debug.Assert(flushTask.IsCompleted);
372+
// If the stream is completed go ahead and call RequestBodyPipe.Writer.Complete().
373+
// Data will still be available to the reader.
374+
if (!endStream)
375+
{
376+
var flushTask = RequestBodyPipe.Writer.FlushAsync();
377+
// It shouldn't be possible for the RequestBodyPipe to fill up an return an incomplete task if
378+
// _inputFlowControl.Advance() didn't throw.
379+
Debug.Assert(flushTask.IsCompleted);
380+
}
376381
}
377382
}
378383
}

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http2/Http2StreamTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,8 +1023,8 @@ public async Task ContentLength_Received_ReadViaPipes()
10231023
await InitializeConnectionAsync(async context =>
10241024
{
10251025
var readResult = await context.Request.BodyPipe.ReadAsync();
1026-
Assert.Equal(12, readResult.Buffer.Length);
10271026
Assert.True(readResult.IsCompleted);
1027+
Assert.Equal(12, readResult.Buffer.Length);
10281028
context.Request.BodyPipe.AdvanceTo(readResult.Buffer.End);
10291029

10301030
readResult = await context.Request.BodyPipe.ReadAsync();

0 commit comments

Comments
 (0)