Harden framing epilog

* Connection no longer needes Frame's processing Task
* Any exceptions from unusual processing is logged
This commit is contained in:
Louis DeJardin 2015-09-17 18:53:35 -07:00
parent 28250d9981
commit 30ec2cb0b1
2 changed files with 72 additions and 54 deletions

View File

@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
SocketInput = new SocketInput(Memory2);
SocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log);
_frame = new Frame(this);
_frameTask = Task.Run(_frame.ProcessFraming);
Task.Run(_frame.ProcessFraming);
_socket.ReadStart(_allocCallback, _readCallback, this);
}

View File

@ -9,6 +9,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.Framework.Logging;
using Microsoft.Framework.Primitives;
// ReSharper disable AccessToModifiedClosure
@ -98,7 +99,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
_responseHeaders.HeaderDate = DateTime.UtcNow.ToString("r");
}
public async Task ProcessFraming()
public async void ProcessFraming()
{
try
{
var terminated = false;
while (!terminated)
@ -157,15 +160,30 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
Reset();
}
// Connection Terminated!
}
catch (Exception ex)
{
Log.LogVerbose("Connection processing ended abnormally", ex);
}
finally
{
try
{
// Inform client no more data will ever arrive
ConnectionControl.End(ProduceEndType.SocketShutdownSend);
// Wait for client to disconnect, or to receive unexpected data
// Wait for client to either disconnect or send unexpected data
await SocketInput;
// Dispose socket
ConnectionControl.End(ProduceEndType.SocketDisconnect);
}
catch(Exception ex)
{
Log.LogVerbose("Connection shutdown abnormally", ex);
}
}
}
public void OnStarting(Func<object, Task> callback, object state)
{