Fix SemaphoreSlim handling of canceled continuation invocations (#34036)
authorStephen Toub <stoub@microsoft.com>
Wed, 25 Mar 2020 02:20:12 +0000 (22:20 -0400)
committerGitHub <noreply@github.com>
Wed, 25 Mar 2020 02:20:12 +0000 (22:20 -0400)
commit9f8990f190868c9e5bf8ed33264fcce3662c4d7b
treef57fa9cf0add4cd0f5522353440d2b90d074fca5
parent25ed30c00a4473510cbeafc406ad7b965e6b23bc
Fix SemaphoreSlim handling of canceled continuation invocations (#34036)

When a SemaphoreSlim.WaitAsync(CancellationToken) completes because the token has cancellation requested, we end up invoking any continuations off of the returned Task synchronously as part of the cancellation registration.  That in turn means that a thread is blocked waiting for that cancelation callback to complete, which can lead to deadlock in niche situations.  We need to force this continuation to be async.
src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs
src/libraries/System.Threading/tests/SemaphoreSlimCancellationTests.cs