Skip to content

Raise the maximum open files limit on Windows #44832

@TheStormN

Description

@TheStormN

What is the problem this feature will solve?

The maximum open files limit is increased to maximum on POSIX platforms here

// Raise the open file descriptor limit.

However, similar functionality is missing for Windows which causes issues with error "EMFILE: too many open files", specially when using webpack.

What is the feature you are proposing to solve the problem?

Use the Windows CRT API to increase the limit. The function is called _setmaxstdio - https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmaxstdio?view=msvc-170

Different versions of Windows support different limits, the default is 512 files with maximum possible number of 8192. My suggestion would be to use loop for probing the maximum possible value, similar to what is currently done for POSIX. I.e. something like that:

static constexpr int MIN_OPEN_FILES_LIMIT = 512;
static constexpr int MAX_OPEN_FILES_LIMIT = 8192;
static constexpr int STEP_OPEN_FILES_LIMIT = 512;
for (int i = MAX_OPEN_FILES_LIMIT; i > MIN_OPEN_FILES_LIMIT; i -= STEP_OPEN_FILES_LIMIT)
{
    if (_setmaxstdio(i) != -1)
        break;
}

What alternatives have you considered?

Unfortunately, it seems there are no alternatives which can raise the limit for process on OS level (like ulimit on some *nix OSes). The process itself have to request it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.stalewindowsIssues and PRs related to the Windows platform.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions