isaacs / node-graceful-fs

fs with incremental backoff on EMFILE
ISC License
1.27k stars 147 forks source link

EMFILE error when attempting to read dir with 10,000 files (Windows 11) #243

Closed Nantris closed 1 year ago

Nantris commented 1 year ago

It always fails at around file 8300-8600. I'm on the latest version already.

Nantris commented 1 year ago

So far I can't determine what operation I'm using that causes this. I suspect it's sort of an edge case, where I just used readdirSync and listed 10,000 files, and then afterward some other filesystem access attempt causes the actual error.

I have never seen this occur on Linux with identical code, but it occurs without fail on Windows. My highest file reached was 9953 out of 10,000, but I can never reach 10,000.

isaacs commented 1 year ago

If you're doing it synchronously, there's nothing that can be done by this module to prevent hitting the file descriptor limit. This lib works by deferring async ops until a fd closes and trying again. But sync stuff is now or never.

10k isn't that much, really, but windows is pretty restrictive sometimes.

isaacs commented 1 year ago

I recommend using the directory streaming iterator API, if you have that many entries to process. You can still iterate over them synchronously.

Nantris commented 1 year ago

Thanks very much for the speedy and sensible reply @isaacs. I'll investigate an alternative approach.