Bug 1888 - Unable to handle handling more the 1024 file handle
Summary: Unable to handle handling more the 1024 file handle
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2011-11-04 18:01 UTC by Torello Querci
Modified: 2013-09-09 11:47 UTC (History)
2 users (show)

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

Code to shot the bug. (1.25 KB, text/x-csharp)
2011-11-04 18:01 UTC, Torello Querci

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 Torello Querci 2011-11-04 18:01:41 UTC
Created attachment 826 [details]
Code to shot the bug.

Trying to handle more that 1024 handle file an exception is raised even if the max number of file limit is increase using "setrlimit". 
Of course mono have the right pcap permission.

Using "strace" on the mono code I have this syscalls:

open("file1021.out", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 1024
close(1024)                             = 0

so seems that mono close the file because open  return value is 1024.

On mailing list Robert Jordan say:

<<This is a bug in Mono's io-layer:


getdtablesize() is returning the max count of possible open
file descriptors *at start-up*, so any later setrlimit has
no effect.

Source code example is included.

The arch where I have this behviour is linux 32bit.
Comment 1 Rodrigo Kumpera 2012-10-29 19:58:14 UTC
This is a limitation of mono, can't you workaround it by setting the rlimit before forking mono?
Comment 2 Torello Querci 2013-02-12 06:22:47 UTC

I'll change the rlimit before starting mono so I'll remove the code that try to change it from C# code.

Comment 3 Rodrigo Kumpera 2013-09-09 11:47:05 UTC
This is a mono limitation, rlimit must be increased for it to work.