basedrop icon indicating copy to clipboard operation
basedrop copied to clipboard

Miri reports Race condition on Collector Test

Open luca3s opened this issue 5 months ago • 1 comments

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.

luca3s avatar Sep 13 '24 18:09 luca3s