-
Notifications
You must be signed in to change notification settings - Fork 7.3k
EMFILE error when using fs.watch on many items #2479
Comments
Yes, |
Ah, thanks for the clarification. |
I'm running node 0.6.9 on linux mint 12. Replacing |
@wombleton: What does the strace log look like? |
|
Heh, that's not quite what I mean. Can you gist the output of |
Ah! Now I know about strace, I had it pegged as a slightly strange contraction. Apologies. |
You're running into a linux-specific system limit, namely the maximum number of inotify instances.
It's something that we can work around. I've opened a libuv issue for it: joyent/libuv#300. |
Fixed in joyent/libuv@d3efefb. |
I'm using fs.watch on node 0.8.2 to watch a directory tree. I'm only watching the directories/subdirectories not each individual file. This is working beatifully on Linux (Ubuntu 10.04). But we are hitting EMFILE error on Mac OS. It looks like this error condition is documented here: https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man2/kqueue.2.html as happening when
Our application does need to work on Mac OS as well as Unix and Windows. So I wonder... is there a way to increase this 'per-process descriptor table' size to something reasonable for our node process? Any suggestions to work around this Mac OS limit welcome. |
PS: I did try a couple of google searches to find the answer to my question, but the most useful result that turned up so far has been this issue :-) |
@kdvolder Try e.g. |
Further note: ulimit command as suggested above doesn't seem to exist on Mac OS. We tried using the equivalent Mac OS command but it didn't seem to work (my guess is because the limit we are hitting is not that of 'open files' but the 'The per-process descriptor table is full.' whatever that is, seems like it is maybe a different limit. |
FYI: command we tried on OS X was this one: Setting it however seemed not have any effect on the limit for fs.watch. Still hitting error at around entry number #249. |
FYI: Decided to resolved this by not using fs.watch on Mac OS. When we detect Mac OS we switch to a polling mechanims. I'd much prefer to use fs.watch of course. But I have not found any way so far to raise the limit. (And even if I could find the magic sudo command, it would be a poor user experience if a user would have to run some 'fix my os' script as sudo before being able to use our stuff. I do understand this isn't a node problem perse, but some type of hard OS limit and so perhaps not a reason to re-open this issue... But maybe there is something that can be done on the node implementation anyway (after all bnoordhus was able to do something to the inotify implementation of fs.watch that seems to work quite nicely on Linux. So I'm hoping someone might come along and do something similar for the Mac OS / kqueue implementation. |
It would be good to have that limit handy under some |
@medikoo That won't happen because the file descriptor limit is a platform specific thing. Non-CRT Windows doesn't really have one, for example. You're free to write an add-on that wraps |
I had the same problem (256 file limit on Mac OS X) and neither of the above worked. However, I found a solution on Superuser.com: http://superuser.com/a/514049 echo 'kern.maxfiles=20480' | sudo tee -a /etc/sysctl.conf
echo -e 'limit maxfiles 8192 20480\nlimit maxproc 1000 2000' | sudo tee -a /etc/launchd.conf
echo 'ulimit -n 4096' | sudo tee -a /etc/profile After rebooting, everything worked fine. |
Some time ago I came up with watch wrapper that uses It works really well on my side. I use it to watch thousands of files at same time on OSX. |
This is to work around an OSx issue that causes EMFILE errors in the default configuration. Ref: nodejs/node-v0.x-archive#2479
A command is quite useful when checking who is consuming inotify resources:
Saw it at http://dev.nethserver.org/issues/2850 |
This problem was not easy to fix with macOS Sierra because of a few changes which make recent instructions no longer value, specifically https://gist.github.com/brennanMKE/f6aa55b452ecda2f4c7a379e21647c88 |
Test case:
With Node 0.6.2 under OS X, I consistently get output of
250
, meaning that 249 files were successfully watched, but anEMFILE
error occurred when trying to watch the 250th. The pertinent part of the stack trace isSeveral folks have experienced the error when using CoffeeScript's watch mode, particularly in a directory that's a git repository (see CoffeeScript issue #1537).
Adding a 100ms interval between each file, I get the same result. So it seems that there's a hard limit on how many files one can watch simultaneously from a Node process on some systems. Is there some way that we can increase or avoid this limit? Pinging @bnoordhuis.
The text was updated successfully, but these errors were encountered: