Fix deadlock when connection is simultaneously aborted and ended (#684).

This commit is contained in:
Cesar Blum Silveira 2016-03-10 14:06:59 -08:00
parent 7c67366e84
commit 8e24c3a708
1 changed files with 13 additions and 12 deletions

View File

@ -151,25 +151,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
} }
public virtual void Abort() public virtual void Abort()
{
lock (_stateLock)
{
if (_connectionState == ConnectionState.CreatingFrame)
{
_connectionState = ConnectionState.ToDisconnect;
}
else
{ {
// Frame.Abort calls user code while this method is always // Frame.Abort calls user code while this method is always
// called from a libuv thread. // called from a libuv thread.
System.Threading.ThreadPool.QueueUserWorkItem(state => System.Threading.ThreadPool.QueueUserWorkItem(state =>
{ {
var connection = (Connection)state; var connection = (Connection)state;
lock (connection._stateLock)
{
if (connection._connectionState == ConnectionState.CreatingFrame)
{
connection._connectionState = ConnectionState.ToDisconnect;
}
else
{
connection._frame.Abort(); connection._frame.Abort();
}
}
}, this); }, this);
} }
}
}
// Called on Libuv thread // Called on Libuv thread
public virtual void OnSocketClosed() public virtual void OnSocketClosed()