From 7b6384635796d99bdb74ba24d80dbdc50731fd5e Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Tue, 12 Apr 2016 14:18:41 -0700 Subject: [PATCH] Prevent crash when aborting connection before Frame is created (#738). --- .../Http/Connection.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs index a5ede79183..fbd690eea7 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Connection.cs @@ -154,9 +154,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { // Frame.Abort calls user code while this method is always // called from a libuv thread. - System.Threading.ThreadPool.QueueUserWorkItem(state => + ThreadPool.Run(() => { - var connection = (Connection)state; + var connection = this; lock (connection._stateLock) { @@ -166,10 +166,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } else { - connection._frame.Abort(); + connection._frame?.Abort(); } } - }, this); + }); } // Called on Libuv thread