Bug 19864 - Overloaded Process.WaitForExit() method returns false immediately
Summary: Overloaded Process.WaitForExit() method returns false immediately
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 3.2.x
Hardware: All Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-05-16 15:44 UTC by cmsano
Modified: 2014-08-15 01:07 UTC (History)
4 users (show)

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

Solution file with simple console application demonstrating issue. (9.21 KB, application/zip)
2014-05-16 15:44 UTC, cmsano

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:

Description cmsano 2014-05-16 15:44:35 UTC
Created attachment 6826 [details]
Solution file with simple console application demonstrating issue.

This works fine on 3.2.6 on OS X 10.9.3. It stopped working on Mono 3.2.7. Verified that this is still not working on 3.4.0.

The issue is simple. The Process.WaitForExit(int) value returns immediately, ignoring the wait value that is passed to it.
Comment 1 Rodrigo Kumpera 2014-05-16 16:31:57 UTC

This has been fixed in mono master. Now it correctly throws InvalidOperationException instead of returning immediately.

The previous behavior was wrong and was fixed in 3.2.7 as you noted.
Comment 2 cmsano 2014-05-16 16:49:45 UTC
Where is the InvalidOperationException the documented behavior?
Comment 3 Rodrigo Kumpera 2014-05-16 18:34:33 UTC
From actually testing the MS implementation.
Comment 4 cmsano 2014-05-16 18:46:03 UTC
I'm confused. The correct implementation is that the method should wait for the specified number of milliseconds. If that amount of time elapses, it should return false. However, what is happening on 3.2.7 is that the method returns false *immediately*. 

Where does the InvalidOperationException come into the picture?
Comment 5 Rodrigo Kumpera 2014-05-16 18:47:08 UTC
Now the correctly behavior, which is throwing an exception, happens.
Comment 6 jmroot 2014-08-11 21:00:07 UTC
This is not the correct behavior for Process.WaitForExit(int32). The correct behavior is for the Process object to return HasExited=false until the Process either exits or the timeout occurs where timeout is the value in milliseconds passed to WaitForExit. Nowhere in .NET does this throw an InvalidOperationException.

This is a regression and this bug should be reactivated and resolved properly. This was working correctly prior to 3.2.7 but is now broken in all versions since.
Comment 7 Rodrigo Kumpera 2014-08-15 01:07:44 UTC
Waiting is only available for process creation and not for shell execution.

Since your sample asks for an app to be launched and not a process to be executed, waiting is not available.

This is the same behavior as of MS and it was introduced to fix issues with shell executing web pages leaving zombies behind.