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

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