Dotnet on OSX is limited to 10240 file handles
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 50/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Domain
- operating-systems
Research direction
Start with the three limit-setting lines in src/coreclr/pal/src/init/pal.cpp and run the C# reproduction that opens 30,000 files on macOS. Trace how the macOS OPEN_MAX and setrlimit behavior affect the runtime, then verify that the released build can exceed 10,240 open files without the reported failure.
Written by the indexing model from the issue text.
Description
Description
Dotnet on mac is limited to only 10240 file handles, this occurs because:
on OS X15.2 OPEN_MAX is defined as:
100:#define OPEN_MAX 10240 /* max open files per process - todo, make a config option? */
I got that from /Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/syslimits.h, another mac user got the same line from sys/resource.h.
The man page for setrlimit mentions:
COMPATIBILITY
setrlimit() now returns with errno set to EINVAL in places that historically succeeded. It no longer accepts "rlim_cur = RLIM_INFINITY" for RLIM_NOFILE. Use "rlim_cur = min(OPEN_MAX, rlim_max)".
Compiling my own version where those three lines are commented out, does result in a dotnet where I can open well over 10k files (my test ran to 250K files before I stopped it).
It would be useful if that artificial limit did not apply to the released version of dotnet.
Reproduction Steps
var directory = "/tmp/openfiles/";
if(Directory.Exists(directory)) Directory.Delete(directory, true);
Directory.CreateDirectory(directory);
var fhs = new List<FileStream>();
for (int i = 0; i < 30000; i++)
{
var file = File.Open(directory + "/" + i + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
fhs.Add(file);
if(i % 1000 == 0) Console.WriteLine($"File {i} opened");
}
Expected behavior
Can open more than 10240 files.
Actual behavior
fails to open more than 10kish files.
Regression?
no
Known Workarounds
none
Configuration
.net 8.0.13
Other information
No response
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·