WSL: open file descriptor limits not updating or being overridden

Windows Version: Microsoft Windows [Version 10.0.14393]

Appending session required pam_limits.so to the /etc/pam.d/common-session and /etc/pam.d/common-session-noninteractive files, and then updating the /etc/security/limits.conf by appending:

*              soft     nofile          35000
*              hard     nofile          35000

and restarting Windows, still does not actually update the ulimit -n value (or ulimit -Hn). It is stuck at 2048 and I am wondering if it can even be changed or if it is being overridden by some process manager, script, or the like?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 2
  • Comments: 15 (1 by maintainers)

Most upvoted comments

I just found a “better” workaround.

We can use prlimit -p PID to set limits for other processes, if we allow that command (or wrap it in a script to further secure it) and execute it with sudo at init, we can effectively change the limits for the running shell.

EG:

❯ prlimit -p "$$"
RESOURCE   DESCRIPTION                             SOFT      HARD UNITS
AS         address space limit                unlimited unlimited bytes
CORE       max core file size                         0 unlimited bytes
CPU        CPU time                           unlimited unlimited seconds
DATA       max data size                      unlimited unlimited bytes
FSIZE      max file size                      unlimited unlimited bytes
LOCKS      max number of file locks held      unlimited unlimited locks
MEMLOCK    max locked-in-memory address space     65536     65536 bytes
MSGQUEUE   max bytes in POSIX mqueues            819200    819200 bytes
NICE       max nice prio allowed to raise             0         0
NOFILE     max number of open files                1024      4096 files
NPROC      max number of processes                31823     31823 processes
RSS        max resident set size              unlimited unlimited bytes
RTPRIO     max real-time priority                     0         0
RTTIME     timeout for real-time tasks        unlimited unlimited microsecs
SIGPENDING max number of pending signals          31823     31823 signals
STACK      max stack size                       8388608 unlimited bytes

$$ resolves to the current process PID

Then change it

sudo prlimit -p "$$" --nofile=10000:10000

And “reload” the shell

exec zsh

Verify

❯ prlimit -p "$$"
RESOURCE   DESCRIPTION                             SOFT      HARD UNITS
AS         address space limit                unlimited unlimited bytes
CORE       max core file size                         0 unlimited bytes
CPU        CPU time                           unlimited unlimited seconds
DATA       max data size                      unlimited unlimited bytes
FSIZE      max file size                      unlimited unlimited bytes
LOCKS      max number of file locks held      unlimited unlimited locks
MEMLOCK    max locked-in-memory address space     65536     65536 bytes
MSGQUEUE   max bytes in POSIX mqueues            819200    819200 bytes
NICE       max nice prio allowed to raise             0         0
NOFILE     max number of open files               10001     10001 files
NPROC      max number of processes                31823     31823 processes
RSS        max resident set size              unlimited unlimited bytes
RTPRIO     max real-time priority                     0         0
RTTIME     timeout for real-time tasks        unlimited unlimited microsecs
SIGPENDING max number of pending signals          31823     31823 signals
STACK      max stack size                       8388608 unlimited bytes

To make it permanent I added sudo prlimit -p "$$" --nofile=10000:10000 to my ~/.zlogin and user ALL=(ALL) NOPASSWD: /usr/bin/prlimit somewhere in the sudoers.d folder

@sunilmut Sure.

I’m using bash on windows to try to build a project with node and webpack. There are many file that are opened during that process. Even with my workaround to set limits in conf files and use su, I was unable to complete the build due to file limit.

ubuntu2004 run "ulimit -n"

That outputs the limit of a different shell (with a different PID) than the one where you changed the limit with prlimit(1). That much is linux-behavior.

Assuming setting the limit in .profile, newspeak would be something like:

C:\> wsl.exe -d Ubuntu /bin/bash -lc "ulimit -n"

Some kind of placeholder feature request to make the default unlimited would probably not be out of line. Or yet another wsl.conf thingy. Absent a more complete resolution #994, anyway.

So I just ran into this today as well.

I found that with those settings, I could do

su - myusername

and for that session the ulimit would be set according to limits.conf

I don’t want to have to do that all the time though…