You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the sake of the example both versions are in the same function, but I originally only had the tokio version, so I don't think that causes the problem.
The directory structure:
.
├── Cargo.lock
├── Cargo.toml
├── dir
│ ├── a
│ ├── b
│ └── c
└── src
└── main.rs
It might be coincidental but in my original code (before reproducing the issue) it was also the 2nd entry alphabetically that was looping infinitely.
I've also tried using the ReadDirStream in tokio-stream and it yields the same result. It would be great to know if I'm misusing the API or if there is any way to fix this, thanks!
The text was updated successfully, but these errors were encountered:
Since with every iteration of the loop you create a new ReadDir object (by calling tokio::fs::read_dir("dir")), you essentially start iterating from the beginning. You should create one ReadDir object and reuse it in the loop. The correct way to iterate over a directory should look like this:
Version
tokio v1.33.0
rustc 1.75.0-nightly (249624b50 2023-10-20)
Platform
Linux nixos 6.5.8 #1-NixOS SMP PREEMPT_DYNAMIC Thu Oct 19 21:11:09 UTC 2023 x86_64 GNU/Linux
Description
When using
tokio::fs::read_dir
, it loops infinitely on one entry. These issues are similar: #5473, rust-lang/rust#50619I tried this code:
For the sake of the example both versions are in the same function, but I originally only had the tokio version, so I don't think that causes the problem.
The directory structure:
I expected to see this happen:
(in some order)
Instead, this happened:
It might be coincidental but in my original code (before reproducing the issue) it was also the 2nd entry alphabetically that was looping infinitely.
I've also tried using the
ReadDirStream
intokio-stream
and it yields the same result. It would be great to know if I'm misusing the API or if there is any way to fix this, thanks!The text was updated successfully, but these errors were encountered: