Skip to content
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

Miri reports Race condition on Collector Test #7

Open
luca3s opened this issue Sep 13, 2024 · 1 comment
Open

Miri reports Race condition on Collector Test #7

luca3s opened this issue Sep 13, 2024 · 1 comment

Comments

@luca3s
Copy link

luca3s commented Sep 13, 2024

Miri currently reports a race condition in the Collector test. I narrowed it down to for _ in 0..100 { collector.collect() } which races with the threads created before that. I have a branch where i changed two Atomic Accesses and miri didn't complain anymore, but i honestly know too little about the linked list used to determine if that really fixes it or just doesn't trigger in that test anymore.


I orginally wanted to build T: ?Sized Support for the Library and just got sidetracked. That PR sadly isn't going happen, as AtomicPtr can't deal with T: ?Sized, due to platform limitations and i can't see a way around that. This (as far as i can see) also makes #3 completely impossible, which i hoped would be able to happen soon (with the Rust for Linux push for custom Smart Pointers).


Miri Output:

Finished test profile [unoptimized + debuginfo] target(s) in 0.00s
Running unittests src/lib.rs (target/miri/aarch64-apple-darwin/debug/deps/basedrop-43f3ef052c3bee08)

running 1 test
test collector::tests::collector ... error: Undefined Behavior: Data race detected between (1) non-atomic write on thread unnamed-97 and (2) atomic store on thread collector::tests::collector at alloc1585770. (2) just happened here
--> src/collector.rs:281:21
|
281 | (*tail).link.next.store(head, Ordering::Relaxed);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) non-atomic write on thread unnamed-97 and (2) atomic store on thread collector::tests::collector at alloc1585770. (2) just happened here
|
help: and (1) occurred earlier here
--> src/collector.rs:99:9
|
99 | (*node).header.link.next = ManuallyDrop::new(AtomicPtr::new(core::ptr::null_mut()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE (of the first span) on thread collector::tests::collector:
= note: inside collector::Collector::collect_one at src/collector.rs:281:21: 281:69
note: inside collector::Collector::collect
--> src/collector.rs:238:15
|
238 | while self.collect_one() {}
| ^^^^^^^^^^^^^^^^^^
note: inside collector::tests::collector
--> src/collector.rs:391:13
|
391 | collector.collect();
| ^^^^^^^^^^^^^^^^^^^
note: inside closure
--> src/collector.rs:362:19
|
361 | #[test]
| ------- in this procedural macro expansion
362 | fn collector() {
| ^
= note: this error originates in the attribute macro test (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with MIRIFLAGS=-Zmiri-backtrace=full for a verbose backtrace

error: aborting due to 1 previous error

error: test failed, to rerun pass --lib

Caused by:
process didn't exit successfully: /Users/lucasbaumann/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner /Users/lucasbaumann/Documents/GitHub/basedrop/target/miri/aarch64-apple-darwin/debug/deps/basedrop-43f3ef052c3bee08 collector (exit status: 1)
note: test exited abnormally; to see the full output pass --nocapture to the harness.

@micahrj
Copy link
Owner

micahrj commented Sep 13, 2024

Interesting, thanks for reporting this! I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants