Call Complete on Http2Stream when stream is done earlier (#7933)

This commit is contained in:
Justin Kotalik 2019-02-26 18:24:35 -08:00 committed by GitHub
parent a2c8a34556
commit bbe4a9d071
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -368,11 +368,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
RequestBodyPipe.Writer.Write(segment.Span); RequestBodyPipe.Writer.Write(segment.Span);
} }
var flushTask = RequestBodyPipe.Writer.FlushAsync();
// It shouldn't be possible for the RequestBodyPipe to fill up an return an incomplete task if // If the stream is completed go ahead and call RequestBodyPipe.Writer.Complete().
// _inputFlowControl.Advance() didn't throw. // Data will still be available to the reader.
Debug.Assert(flushTask.IsCompleted); if (!endStream)
{
var flushTask = RequestBodyPipe.Writer.FlushAsync();
// It shouldn't be possible for the RequestBodyPipe to fill up an return an incomplete task if
// _inputFlowControl.Advance() didn't throw.
Debug.Assert(flushTask.IsCompleted);
}
} }
} }
} }

View File

@ -1023,8 +1023,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
await InitializeConnectionAsync(async context => await InitializeConnectionAsync(async context =>
{ {
var readResult = await context.Request.BodyPipe.ReadAsync(); var readResult = await context.Request.BodyPipe.ReadAsync();
Assert.Equal(12, readResult.Buffer.Length);
Assert.True(readResult.IsCompleted); Assert.True(readResult.IsCompleted);
Assert.Equal(12, readResult.Buffer.Length);
context.Request.BodyPipe.AdvanceTo(readResult.Buffer.End); context.Request.BodyPipe.AdvanceTo(readResult.Buffer.End);
readResult = await context.Request.BodyPipe.ReadAsync(); readResult = await context.Request.BodyPipe.ReadAsync();