Skip to content

src: raise the maximum open files limit on Windows#63643

Open
medns wants to merge 1 commit into
nodejs:mainfrom
medns:win-raise-max-stdio
Open

src: raise the maximum open files limit on Windows#63643
medns wants to merge 1 commit into
nodejs:mainfrom
medns:win-raise-max-stdio

Conversation

@medns
Copy link
Copy Markdown
Contributor

@medns medns commented May 29, 2026

On Windows, libuv uses the CRT's _open_osfhandle when opening files. This is constrained by the CRT's maxstdio limit, which defaults to 512, often causing "EMFILE: too many open files" errors for heavy workloads (such as modular building via webpack).

This PR raises this limit on Windows up to the CRT maximum (8192) by invoking _setmaxstdio during PlatformInit, mirroring the behavior on POSIX platforms.

Fixes: #44832

Copilot AI review requested due to automatic review settings May 29, 2026 11:50
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels May 29, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR increases the Windows CRT stream I/O limit during platform initialization (unless kNoAdjustResourceLimits is set) to reduce “too many open files” (EMFILE) failures in file-heavy workloads.

Changes:

  • Add Windows-specific initialization that calls _setmaxstdio to raise the CRT max open streams limit (up to 8192), with a fallback loop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/node.cc Outdated
Comment thread src/node.cc Outdated
@medns medns force-pushed the win-raise-max-stdio branch 3 times, most recently from c42204d to 5c81dd3 Compare May 29, 2026 12:04
On Windows, libuv uses the CRT's _open_osfhandle when opening files.
This is constrained by the CRT's maxstdio limit, which defaults to 512,
often causing "EMFILE: too many open files" errors for heavy workloads.

This commit raises this limit on Windows up to the CRT maximum (8192)
by invoking _setmaxstdio during PlatformInit, mirroring the POSIX
behavior.

Fixes: nodejs#44832
Signed-off-by: 郑苏波 (Super Zheng) <superzheng@tencent.com>
@aduh95
Copy link
Copy Markdown
Contributor

aduh95 commented May 29, 2026

Can we add a test?

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.29%. Comparing base (dbec31c) to head (5c81dd3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63643      +/-   ##
==========================================
+ Coverage   90.28%   90.29%   +0.01%     
==========================================
  Files         730      730              
  Lines      234802   234802              
  Branches    43953    43953              
==========================================
+ Hits       211991   212023      +32     
+ Misses      14530    14498      -32     
  Partials     8281     8281              
Files with missing lines Coverage Δ
src/node.cc 76.93% <ø> (ø)

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raise the maximum open files limit on Windows

5 participants