New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Win 10 pro still getting EMFILE: too many open files
error.
#194
Comments
+1, same issue on WSL 2 on Windows 10. @stevemarksd: I had to globally patch |
Have the same issue as @stevemarksd @strarsis , what do you mean with "globally patch fs"? Is it the same as calling |
@AndreasWJ: No, it isn't the same. The global patch approach will replace all uses of |
Thanks for clearing it up! I've patched it globally through the code below, but it still doesn't work. How did you solve it?
Sorry for the inconvience. I'm fairly new to Javascript |
You should do this in top level of your app and as soon as possible var realFs = require('fs')
var gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(realFs) You use |
I put the snippet first in my index.js, however, it throws the same error. I use the module called 'vpk'(link) which extracts thousands of game files from Valve games. In the process of extracting these I'm reading thousands of files, hence the error being thrown. Unfortunantely, the module is kind of niche and it doesn't support a |
|
I really appreciate the help! I'm clueless with these things. Here's the stack trace:
For reference, here is the line of code supposedly throwing the error:
I tried removing the specific file that's involved when the error is thrown; 'data/resource/flash/econ/stickers/cologne2015/sig_kennys_gold_large.png'. Just to rule it out, and it made no difference. Is it impossible to "switch out requires" in JBinary before loading requiring the vpk module? Essentially what I've done so far with my Proxy solution. The idea was to replace all imports like |
So |
Plain Here is Handler:105-Handler:109:
Where |
@AndreasWJ: But when the |
@strarsis: I've "globally" patched fs in my index.js, the first line that's executed is the patch:
I've manually patched the
However, weirdly enough the error is thrown from exactly the same line of code like before; Handler:107. Here's the stack trace:
|
@strarsis: As for node version I'm using v15.4.0. Edit: Downloaded the latest LTS; v14.15.3. For some reason I had an experimental version before, no idea how.
|
@AndreasWJ: This is strange, but it looks as that line still doesn't use the |
@strarsis: I couldn't tell you what WSL I'm on, I have the standard 64 bit Windows 10 installer if that helps 😅. I completely removed bluebird, it was a leftover from another file, unneeded in Handler.js as there are no "Async" suffixes. And it is good to rule out... Yet the same error persists, and the same line. I do agree, I have no idea why |
Might have found out why Therefore, there's another problem. I've successfully globally patched @strarsis: Is this something you're aware of? Or am I completely lost? |
As I investigated error is thrown by function openSync(path, flags, mode) {
path = getValidatedPath(path);
const flagsNumber = stringToFlags(flags);
mode = parseFileMode(mode, 'mode', 0o666);
const ctx = { path };
const result = binding.open(pathModule.toNamespacedPath(path),
flagsNumber, mode,
undefined, ctx);
handleErrorFromBinding(ctx);
return result;
} So it looks as clear bug on |
I'm almost positive it is impossible to 'fix' an EMFILE error given by sync functions. EMFILE means that the current process is out of FD's. It's impossible for the current process to close any existing FD's while ENFILE is a bit different, in this case we could have a loop that wastes 100% of CPU cycles in the hope that another process closes some FD's, but that is a really bad/wasteful idea which I don't think is open for consideration. Not having retry cycles to handle FD exhaustion from Sync functions is not a code bug, though I'll leave this issue open as the documentation can probably be improved to make this clear. My advice if you are facing this problem you need to avoid sync functions, or determine why your system is overloaded. |
@coreyfarrell indeed, that's a very good point. Still situation could be improved, and make such crashes less likely, if for async function we try to keep taken descriptors few counts below the maximum allowed. Then there's always some room for eventual sync processors, which come to play (also in most circumstances sync processors release taken descriptor immediately). Of course there's no perfect solution to that. First we need to reach the limit, to know what's the process limit, and only afterwards we can workout the room for eventual sync processors. |
e.g. I was also using this solution in a past, which after limit is reached, simply keeps usage below the limit (without falling into EMFILE errors), this one could be relatively easily improved to leave room for sync processors |
@medikoo I appreciate you trying but we're not open to making this module attempt to reserve FD's. This module is VERY heavily used and even the simplest changes result in regressions, often for other widely used packages. What you are proposing would be breaking and a very wide-reaching change. Further making this error less likely would only give a false security and encourage skipping necessary error checking. |
Do you mean regressions caused by eventual not intentional bugs introduced. Or do you envision the scenario where keeping used FD's few counts below the limit (with proper implementation) can break users applications? Anyway such change can always be proposed with major version bump, and I agree that this comes as significant change that deserves a major bump. I also think it can only work with globally applied patch, so it could be specific to it, and even could be behind the option. |
@AndreasWJ: Just was notified about this issue again. Yes, it appears that the sync methods are not patched. |
Thanks for the reply @strarsis. Will fork and modify needed modules myself! |
I've added this at the root of my app
But I'm still getting
EMFILE: too many open files
error.Any ideas what else can I do? Win 10 pro
The text was updated successfully, but these errors were encountered: