From 792f3ad08909c4ecd872eea043076447f1d70ae4 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Thu, 17 Mar 2016 23:01:42 -0700 Subject: [PATCH 1/2] Fix race preventing handling of the last request sent over a connection We need to attempt to consume start lines and headers even after SocketInput.RemoteIntakeFin is set to true to ensure we don't close a connection without giving the application a chance to respond to a request sent immediately before the a FIN from the client. --- .../Http/FrameOfT.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 053688b587..40a160a0fe 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -37,8 +37,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (SocketInput.RemoteIntakeFin) { + if (TakeStartLine(SocketInput)) + { + break; + } + return; } + await SocketInput; } @@ -48,8 +54,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (SocketInput.RemoteIntakeFin) { + if (TakeMessageHeaders(SocketInput, FrameRequestHeaders)) + { + break; + } + return; } + await SocketInput; } From fd70fb732d28d2c8a2ef871f6ef0d9487a6de46e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 22 Mar 2016 17:55:21 -0700 Subject: [PATCH 2/2] Add explanatory comments for previous commit. --- src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs index 40a160a0fe..21eeaa1c6a 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs @@ -37,6 +37,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (SocketInput.RemoteIntakeFin) { + // We need to attempt to consume start lines and headers even after + // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a + // connection without giving the application a chance to respond to a request + // sent immediately before the a FIN from the client. if (TakeStartLine(SocketInput)) { break; @@ -54,6 +58,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { if (SocketInput.RemoteIntakeFin) { + // We need to attempt to consume start lines and headers even after + // SocketInput.RemoteIntakeFin is set to true to ensure we don't close a + // connection without giving the application a chance to respond to a request + // sent immediately before the a FIN from the client. if (TakeMessageHeaders(SocketInput, FrameRequestHeaders)) { break;