Bug 15956 - Task.WhenAll<T> task hangs when list of tasks to wait for is empty
Summary: Task.WhenAll<T> task hangs when list of tasks to wait for is empty
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-11-06 06:14 UTC by Tammo Hinrichs
Modified: 2013-11-12 03:39 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test case for Task.WhenAll<T> with empty argument list (452 bytes, text/plain)
2013-11-06 06:14 UTC, Tammo Hinrichs
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Tammo Hinrichs 2013-11-06 06:14:26 UTC
Created attachment 5348 [details]
Test case for Task.WhenAll<T> with empty argument list

When using Task.WhenAll<T> with an empty argument list the returned task never finishes.

This is in conflict with the non-generic Task.WhenAll and also the MSDN documentation: "If the supplied array/enumerable contains no tasks, the returned task will immediately transition to a RanToCompletion state before it's returned to the caller. The returned TResult[] will be an array of 0 elements."

I've attached a repro case that should be trivial enough to understand without any further documentation :)
Comment 1 Tammo Hinrichs 2013-11-06 07:31:45 UTC
Also, fixing it was trivial: https://github.com/mono/mono/pull/799

Explanation: The Task returned by WhenAllCore is normally set to finished state by WhenAllContinuation.Execute(). But when there's no task to be continued, this never gets called and that's it.

The non-generic WhenAllCore has a mechanism that checks for this condition and also if all tasks have already run but that would be harder to implement because the generic version needs to fill the result array. So I think simply testing for an empty input array and returning a finished task object is the simplest solution here.