diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/InMemoryTransportConnection.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/InMemoryTransportConnection.cs index b6f510a722a4..086694908360 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/InMemoryTransportConnection.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/TestTransport/InMemoryTransportConnection.cs @@ -63,13 +63,11 @@ public override void Abort(ConnectionAbortedException abortReason) public void OnClosed() { - if (_isClosed) + if (Interlocked.CompareExchange(ref _isClosed, true, false) == true) { return; } - _isClosed = true; - ThreadPool.UnsafeQueueUserWorkItem(state => { state._connectionClosedTokenSource.Cancel();