From c22f8f5c59cb5d941e243fd6a794f4d593fe8ada Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Mon, 24 Apr 2017 16:47:48 -0700 Subject: [PATCH] Fix potential race in LibuvThread.StopAsync (#1756) --- .../Internal/LibuvThread.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs index e816d2630b..f5e4909635 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv/Internal/LibuvThread.cs @@ -102,10 +102,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal { var stepTimeout = TimeSpan.FromTicks(timeout.Ticks / 3); - Post(t => t.AllowStop()); - if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) + try { - try + Post(t => t.AllowStop()); + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { Post(t => t.OnStopRude()); if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) @@ -117,12 +117,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal } } } - catch (ObjectDisposedException) + } + catch (ObjectDisposedException) + { + if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) { - if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false)) - { - _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); - } + _log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread."); } } }