Fix UnobservedTaskException from SemaphoreSlim.WaitAsync (#60890)
authorStephen Toub <stoub@microsoft.com>
Fri, 5 Nov 2021 15:06:44 +0000 (11:06 -0400)
committerGitHub <noreply@github.com>
Fri, 5 Nov 2021 15:06:44 +0000 (11:06 -0400)
commitfd072149d951bfaf866fcdab93366ca0149a05e6
tree1adf3846862d100c5227f709ae640ce6d09b09a0
parent39a4a705894651490d36c3e4822f1953ef557d8b
Fix UnobservedTaskException from SemaphoreSlim.WaitAsync (#60890)

* Fix UnobservedTaskException from SemaphoreSlim.WaitAsync

If a SemaphoreSlim.WaitAsync times out, it correctly returns false, but it also results in TaskScheduler.UnobservedTaskException being raised unexpectedly, due to internal use of a faulted task whose exception isn't observed.  This fixes that by marking any such exceptions as having been observed.

* Fix wasm build
src/libraries/System.Private.CoreLib/src/System/Threading/SemaphoreSlim.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs
src/libraries/System.Threading/tests/SemaphoreSlimTests.cs