From: Ben Adams Date: Mon, 10 Aug 2020 22:34:07 +0000 (+0100) Subject: Fix DelayPromise constructor race condition (#40356) X-Git-Tag: submit/tizen/20210909.063632~6101 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e5779655a7b0f885cc8870a0c6f8502fc3d00dc5;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix DelayPromise constructor race condition (#40356) --- diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs index 3b34af0..13b4914 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @@ -5382,9 +5382,9 @@ namespace System.Threading.Tasks if (millisecondsDelay != Timeout.Infinite) // no need to create the timer if it's an infinite timeout { _timer = new TimerQueueTimer(state => ((DelayPromise)state!).CompleteTimedOut(), this, (uint)millisecondsDelay, Timeout.UnsignedInfinite, flowExecutionContext: false); - if (IsCanceled) + if (IsCompleted) { - // Handle rare race condition where cancellation occurs prior to our having created and stored the timer, in which case + // Handle rare race condition where completion occurs prior to our having created and stored the timer, in which case // the timer won't have been cleaned up appropriately. This call to close might race with the Cleanup call to Close, // but Close is thread-safe and will be a nop if it's already been closed. _timer.Close();