Bug/AWS

[Serverless] "too many open files" >> WSL Ubuntu Open File Limit

brightlightkim 2022. 5. 6. 06:43

If you are seeing the message with "EMFILE: too many open files" in your deployment, that's because your current system of open files is limited.

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 101974
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 4096
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 101974
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

In my case it was only 4096, which is not enough for node deployment sometimes.

 

So to change the one,

You first need to check if you are logged in as a root or user in Ubuntu

$ whoami
[It will print your user name or root]

If it's the user, you need to login to the root

$sudo su -
//It will make you to login as a root in Ubuntu

Then change the file /etc/security/limits.conf

//you can type 
$vi /etc/security/limits.conf

When the file is opened, type the following

* soft nofile 32768
* hard nofile 65536

Note: If you are not used to using vim,

press i for inserting input

arrows to move around

when it's done, press esc key

and type shift+zz

(so type ZZ with the shift key)

and it will save the values.

 

You can even type the nofile to 200000 just in case.

 

Then log in as the user ID (Your one)

$su [username] 
//please don't type the brackets
//if your username is sun
//Then just type su sun

Then restart the system (either delete it in task manager and run it again in visual studio)

and run the command. You will find that it will work now.