Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Too Many Files (EMFILE Error) in Windows 7

I am using Node.js (0.10.31) and Gulp (3.8.8) to automating some tasks in Windows 7 but I've faced following error:

events.js:72
    throw er; // Unhandled 'error' event
          ^
Error: EMFILE, open 'c:\myproject\package.json'

I have moved the project to Ubuntu and fix that using ulimit -n command but still curious about how to solve that in Windows.

Now, first I want to know whether there is any limitation that prevent opening more files/sockets in Windows 7 that cause EMFILE error or not?

Secondly, if yes, how can I change that limitation?

like image 984
R‌‌‌.. Avatar asked Aug 11 '15 03:08

R‌‌‌..


People also ask

What is Emfile error?

EMFILE means error maximum files which indicates that the OS is denying your program to open more file descriptors.27-Apr-2012.

What is Emfile?

emFile is a fail-safe file system for embedded systems and applications which can be used on any storage device. It is a high-performance library optimized for minimum memory consumption in RAM, ROM, high speed, and versatility working on any embedded device.


1 Answers

There is a limitation inside the VSC++ runtime. An application can only open 512 file descriptors through the runtime, although the value can be increased to 2048 if the application calls _setmaxstdio (which I think node doesn't). (This is a somewhat simplified explanation, for more details see here.) You can't change this limitation directly (you could only raise the 512 to 2048 if you would get node to call this function for you somehow).

However you wrote you are using node v0.10.31 which is pretty old. As far as I know (although I'm not 100% certain about that), node had in the meantime switched from using the VSC++ runtime for File I/O to native WinAPI calls which do not have this limitation, so you could try the latest node version if that's an option for you.

like image 136
CherryDT Avatar answered Oct 04 '22 02:10

CherryDT