-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Detect possible deadlocks when instantiating a parallel iterator.
Deadlocks can happen if the producer for results doesn't start as there is no free thread on the rayon pool, and the only way for it to become free is if the iterator produces results. We now offer a `busy_timeout` in the relevant variants of the `Parallelism` enumeration to allow controlling how long we will wait until we abort with an error.
- Loading branch information
Showing
6 changed files
with
112 additions
and
55 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use jwalk::WalkDir; | ||
use rayon::prelude::*; | ||
|
||
#[test] | ||
fn works() { | ||
rayon::ThreadPoolBuilder::new() | ||
.num_threads(1) | ||
.build_global() | ||
.expect("Failed to initialize worker thread pool"); | ||
// Does not finish if jwalk uses shared pool with 1 thread, but we can detect this issue and signal this with an error. | ||
(0..=1) | ||
.collect::<Vec<usize>>() | ||
.par_iter() | ||
.for_each(|_round| { | ||
for entry in WalkDir::new(".").parallelism(jwalk::Parallelism::RayonDefaultPool { | ||
busy_timeout: std::time::Duration::from_millis(10), | ||
}) { | ||
match entry { | ||
Ok(_) => panic!("Must detect deadlock"), | ||
Err(err) | ||
if err.io_error().expect("is IO").kind() == std::io::ErrorKind::Other => {} | ||
Err(err) => panic!("Unexpected error: {:?}", err), | ||
} | ||
} | ||
}); | ||
} |
This file contains 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