-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
walk_dir uses too many file descriptors #23715
Comments
Exactly the same issue exists with depth-first traversals as well, when directory structure could be deeper than RLIMIT_NOFILE. I do not think I’d want to see paths being stored in memory either. |
A hybrid approach similar to one taken by |
Oh dear I definitely didn't intend for this to happen! I intended for it to only have an active list of directories proportional to the current depth. I do agree with @nagisa that a DFS wouldn't solve the problem, but I suspect directories are more often wide than deep. I also would love to add tons of configuration to |
Yeah, this sounds like the problem I'm seeing for sure. 👍 |
This is fixed in an external crate: http://burntsushi.net/rustdoc/walkdir/ |
The in-tree walk_dir is now deprecated, in favor of @BurntSushi 's crate. |
The current implementation of
fs::walk_dir
is breadth first, with a file descriptor being held for each directory that has been found but not yet traversed. This can lead to "Too many open files" errors.On my mac, the default limit for file descriptors is 256. A
.git/objects
directory can contain 257 directories, so with a breadth first search with a queue of ReadDir objects (each of which holds a DIR), this limit can easily be hit.I can see two possible solutions: either changing the queue to hold paths rather than ReadDir objects, or switching to depth first traversal.
I hit this error running the following on a directory tree containing a
.git
directory, and with a max directory depth of 9.The text was updated successfully, but these errors were encountered: