Repository navigation
Fix stack overflow when filtering many entries (#13) and prepare 2.2.0 - #20
Merged
Merged
Conversation
Walking recursed through boxed futures for each filtered-out entry, overflowing small stacks such as tokio worker threads. Rewrite the traversal as a loop and add a regression test. Fixes #13
Reading them was wasted work and could yield IO errors for directories the user asked to skip.
Windows CI does not run the unix-only error tests, which dropped line coverage below 90% after the traversal rewrite. Cover the read_dir error path portably and factor the IO error construction into a helper.
ririsoft
force-pushed
the
fix/issue-13-stack-overflow
branch
from
September 28, 2026 13:37
2bb6f7c to
7aa5cee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13.
Problem
Filtering out many consecutive entries with
WalkDir::filteroverflowed the stack on threads with a small stack, such as tokio worker threads. The privatewalkandwalk_entryfunctions called each other recursively through boxed futures, once for every ignored entry. As a result, stack depth grew with the number of filtered-out entries. Without a filter, each entry is returned right away, which is why the unfiltered case worked.Changes
stream::unfold, with no recursion and no per-entry boxing. The public API is unchanged.IgnoreDir:read_dirwas called on them even though they were never walked. That was wasted work and could return IO errors, such as permission denied, for directories the user asked to skip.Tests
tests/issue_13_stack_overflow.rsis a regression test. It runsWalkDirinsidetokio::spawnon a runtime with a 512 KiB stack, with 4,000 ignored entries.IgnoreandIgnoreDir.tokiois added as a dev-dependency only.read_direrrors on subdirectories. It also keeps line coverage above 90% on Windows, where the unix-only tests don't run.IgnoreDirproduces no error.cargo test,cargo clippy --all-targets -- -D warnings,cargo fmt --checkandcargo publish --dry-runall pass.cargo semver-checksagainst 2.1.0 reports no semver update required.