Whilst writing some unit tests I hit the upper limit for too many open files (Debian VM) - "failed to open stream: Too many open files"

Other than a restart, is there any way to clear this block? (i.e. will these open, but unaccessed, files be cleaned up over time?)

Fyi - I'd like to know because I want to setup a continuous integration server for unit testing, and if a reboot is the only way to clear this problem then I need to find a different way of approaching certain unit tests.


Not unless you close them or the process that owns them dies.

It's possible that the user that you are using to run the tests is constrained by ulimits as to how many files they can open.


Did you try to increase the maximum open files for the user under which you run the tests ?

To see how many open files the user has (soft and hard):

# ulimit -Hn
# ulimit -Sn

Also it normal that sometimes you need to increase the global max open files for the system. So try with that and find out if it helps.

# sysctl -w fs.file-max=100000

If you wanna permanently change the max open files you need to edit /etc/sysctl.conf file and add/change the following line

fs.file-max = 100000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.