diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 8dc2670a6a..2f26f68348 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -279,8 +279,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { await ProduceEnd(); - // Finish reading the request body in case the app did not. - await messageBody.Consume(); + if (_keepAlive) + { + // Finish reading the request body in case the app did not. + await messageBody.Consume(); + } } _requestBody.StopAcceptingReads(); diff --git a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs index c125da04b5..861a2a84c3 100644 --- a/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -88,6 +88,37 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests return TestRemoteIPAddress("[::1]", "[::1]", "::1", "8792"); } + [ConditionalFact] + [FrameworkSkipCondition(RuntimeFrameworks.Mono, SkipReason = "Test hangs after execution on Mono.")] + public async Task DoesNotHangOnConnectionCloseRequest() + { + var config = new ConfigurationBuilder().AddInMemoryCollection( + new Dictionary { + { "server.urls", "http://localhost:8791" } + }).Build(); + + var builder = new WebHostBuilder(config) + .UseServerFactory("Microsoft.AspNet.Server.Kestrel") + .UseStartup(app => + { + app.Run(async context => + { + var connection = context.Connection; + await context.Response.WriteAsync("hello, world"); + }); + }); + + using (var app = builder.Build().Start()) + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Connection.Clear(); + client.DefaultRequestHeaders.Connection.Add("close"); + + var response = await client.GetAsync("http://localhost:8791/"); + response.EnsureSuccessStatusCode(); + } + } + private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress, string port) { var config = new ConfigurationBuilder().AddInMemoryCollection(