[Mono-bugs] [Bug 73227][Wis] New - System.Diagnostics.Process.WaitForExit hang

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 2 Mar 2005 14:43:28 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by jonpryor@vt.edu.

http://bugzilla.ximian.com/show_bug.cgi?id=73227

--- shadow/73227	2005-03-02 14:43:28.000000000 -0500
+++ shadow/73227.tmp.5003	2005-03-02 14:43:28.000000000 -0500
@@ -0,0 +1,84 @@
+Bug#: 73227
+Product: Mono: Class Libraries
+Version: 1.1
+OS: other
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: jonpryor@vt.edu               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: System.Diagnostics.Process.WaitForExit hang
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+System.Diagnostics.Process.WaitForExit hangs if the sub-process generates
+more than 4096 bytes of output.
+
+Steps to reproduce the problem:
+1. Compile the following test program:
+
+	// file: sdp.cs
+	using System;
+	using System.Diagnostics;
+
+	class Test {
+		public static void Main (string[] args) {
+			Process tarProcess = new Process();
+
+			tarProcess.StartInfo.FileName = "cat";
+			tarProcess.StartInfo.Arguments = args[0];
+
+			tarProcess.StartInfo.RedirectStandardOutput = true;
+			tarProcess.StartInfo.UseShellExecute = false;
+
+			bool a = tarProcess.Start();
+
+			Console.WriteLine(a);
+
+			tarProcess.WaitForExit();
+			Console.WriteLine ("finished; r=" + tarProcess.ExitCode);
+			string o = tarProcess.StandardOutput.ReadToEnd ();
+			Console.WriteLine ("output=" + o);
+		}
+	}
+
+2. Create a text file at least 4096 bytes in size (51 lines of 80-column
+text will do)
+3. Start the test program with: mono sdp.exe some-file.txt
+
+Actual Results:
+
+The program hangs.  Even better, if you suspend the process (Ctrl+Z) and
+list processes (ps -aux | grep cat), you'll see that the create subprocess
+is sleeping.
+
+Expected Results:
+
+No hang, and the contents of some-file.txt copied to the console.
+
+How often does this happen? 
+
+Always.
+
+Additional Information:
+
+This appears to be due to mono/mono/metadata/process.c:
+ves_icall_System_Diagnostics_Process_WaitForExit_internal, which does a
+WaitForSingleObjectEx for an indefinite wait.  Meanwhile, the child process
+is attempting to write to its stdout, but since stdout is a pipe (default
+to 4kb buffer size) and the pipe isn't being emptied, the child sleeps. 
+Since the parent is blocked, and the child is blocked, we have deadlock.  Yech.
+
+The correct fix would be for the parent process to continually read
+StandardOutput, if necessary, so that the child is blocked on the parent. 
+How to do this while supporting the WaitForExit(int) overload is an
+excercise for the bug-fixer. :-)