Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Fix hang on Connection: close requests. (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesar Blum Silveira committed Nov 21, 2015
1 parent 9d85263 commit e4fd91b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs
Expand Up @@ -279,8 +279,11 @@ public async Task RequestProcessingAsync()
{
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();
Expand Down
Expand Up @@ -88,6 +88,37 @@ public Task RemoteIPv6Address()
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<string, string> {
{ "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(
Expand Down

1 comment on commit e4fd91b

@jincod
Copy link

@jincod jincod commented on e4fd91b Nov 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it fix this issue?

Please sign in to comment.