From 7b315d2470e57ae832a763a2338b0a275f39eb8f Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 14 Oct 2015 15:29:30 -0700 Subject: [PATCH] Close connection gracefully in Frame.ProduceEnd - Try sending a FIN before closing the socket - Don't attempt to send a FIN twice for the same connection --- src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index 161536aef3..22daa279a2 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -449,7 +449,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http if (_responseStarted) { // We can no longer respond with a 500, so we simply close the connection. - ConnectionControl.End(ProduceEndType.SocketDisconnect); + _keepAlive = false; return; } else @@ -475,7 +475,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http WriteChunkedResponseSuffix(); } - ConnectionControl.End(_keepAlive ? ProduceEndType.ConnectionKeepAlive : ProduceEndType.SocketShutdownSend); + if (_keepAlive) + { + ConnectionControl.End(ProduceEndType.ConnectionKeepAlive); + } } private Tuple, IDisposable> CreateResponseHeader(