Fix leak in Task.WaitAny(..., int) (dotnet/coreclr#10331)
authorStephen Toub <stoub@microsoft.com>
Wed, 22 Mar 2017 06:09:22 +0000 (02:09 -0400)
committerJan Kotas <jkotas@microsoft.com>
Wed, 22 Mar 2017 06:09:22 +0000 (23:09 -0700)
commit195450160a9bc744d4c91f4f8c02b0523048018a
treef3ff430897ff2033649aa06fd5fb9874b48de590
parent13a4c28504877a71aebe457bbab1dc3a5ed4f9ca
Fix leak in Task.WaitAny(..., int) (dotnet/coreclr#10331)

WaitAny is effectively built on top of WhenAny, creating a continuation from the supplied tasks and then blocking on that continuation.  When a timeout is provided, it blocks with that timeout.  But if it doesn't complete within the timeout, it ends up leaking the continuations it created into the constituent tasks.  The fix is simply to force the returned continuation to complete, such that its continuation logic does all of the appropriate cleanup.

Commit migrated from https://github.com/dotnet/coreclr/commit/d6e9a08a70dab11ddc845fb0ccf36aa436e9ebec
src/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs
src/coreclr/src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs