8000 fix double panic when exceeding the branch limit in `Drop` by hawkw · Pull Request #245 · tokio-rs/loom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix double panic when exceeding the branch limit in Drop #245

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

Merged
merged 3 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/rt/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@ pub(crate) enum Thread {
macro_rules! assert_path_len {
($branches:expr) => {{
assert!(
$branches.len() < $branches.capacity(),
"Model exeeded maximum number of branches. This is often caused \
// if we are panicking, we may be performing a branch due to a
// `Drop` impl (e.g., for `Arc`, or for a user type that does an
// atomic operation in its `Drop` impl). if that's the case,
// asserting this again will double panic. therefore, short-circuit
// the assertion if the thread is panicking.
$branches.len() < $branches.capacity() || std::thread::panicking(),
"Model exceeded maximum number of branches. This is often caused \
by an algorithm requiring the processor to make progress, e.g. \
spin locks.",
);
Expand Down
13 changes: 13 additions & 0 deletions tests/double_panic_in_drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[test]
#[should_panic]
fn double_panic_at_branch_max() {
let mut builder = loom::model::Builder::new();
builder.max_branches = 2;

builder.check(|| {
let _arc = loom::sync::Arc::new(());
loom::thread::yield_now();
loom::thread::yield_now();
loom::thread::yield_now();
});
}
0