Bug 40643

Summary: Process leaking handles leads to "too many open files"
Product: [Mono] Class Libraries Reporter: Mike Voorhees <michaelv>
Component: SystemAssignee: Ludovic Henry <ludovic>
Status: RESOLVED FIXED    
Severity: major CC: eric, joncham, masafa, miguel, mono-bugs+mono
Priority: High    
Version: master   
Target Milestone: Untriaged   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Compile and run to reproduce

Description Mike Voorhees 2016-04-22 15:46:03 UTC
Created attachment 15819 [details]
Compile and run to reproduce

When running processes with output redirected, you will eventually run into the following exception :

Unhandled Exception:
System.IO.IOException: Too many open files
  at System.Diagnostics.Process.CreatePipe (System.IntPtr& read, System.IntPtr& write, System.Boolean writeDirection) <0x102c0af70 + 0x001f0> in <filename unknown>:0 
  at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) <0x102c09e40 + 0x00397> in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Too many open files
  at System.Diagnostics.Process.CreatePipe (System.IntPtr& read, System.IntPtr& write, System.Boolean writeDirection) <0x102c0af70 + 0x001f0> in <filename unknown>:0 
  at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) <0x102c09e40 + 0x00397> in <filename unknown>:0


On my system, with the repro case attached, it took until run 592 to happen.

With mono 3.12.1 and 4.2.2 this test case passes.

It looks like this was introduced during some refactoring to the Process class.  Maybe the FIXME's in https://github.com/mono/mono/blob/master/mcs/class/System/System.Diagnostics/Process.cs are related.
Comment 1 Ludovic Henry 2016-04-24 18:01:57 UTC
Hi Mike,

Thank you for the report. You are right, the bug comes from one of the FIXME in https://github.com/mono/mono/blob/master/mcs/class/System/System.Diagnostics/Process.cs. I am currently trying to figure out why we need that in the first place.

Thank you,
Ludovic
Comment 2 Ludovic Henry 2016-04-24 20:16:53 UTC
This is fixed with https://github.com/mono/mono/pull/2946
Comment 3 Mike Voorhees 2016-04-25 11:53:05 UTC
Thanks!
Comment 4 eric 2016-06-23 14:42:49 UTC
What release was this pushed to, I don't see this in the latest release.  Also if I look at the modified files from this PR, I don't see it in the master branch anymore.