moka
moka copied to clipboard
Data race found by `miri test`
Commit: d74d1e3c7cd922577767c8c2f9a8bdf7b7018e69
Rust Version: cargo 1.70.0-nightly (0e474cfd7 2023-03-31)
OS: macOS 13.4
CPU: Apple M2 Max
Running cargo +nightly miri test
in the root of the crate, fails on the first test:
test cht::map::bucket::tests::get_insert_remove
with the error:
error: Undefined Behavior: Data race detected between (1) Write on thread `<unnamed>` and (2) Read on thread `<unnamed>` at alloc218679. (2) just happened here
I also disabled the race detector with MIRIFLAGS="-Zmiri-disable-data-race-detector"
, but when running with this flag the test never completes.
Note: I started looking into Moka because recently we tried using it in https://github.com/MaterializeInc/materialize/pull/19614, but had to revert it because we were observing memory corruption.
Full Stack Trace:
error: Undefined Behavior: Data race detected between (1) Write on thread `<unnamed>` and (2) Read on thread `<unnamed>` at alloc218679. (2) just happened here
--> /Users/parker.timmerman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.15/src/atomic.rs:204:9
|
204 | &*(ptr as *const T)
| ^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Write on thread `<unnamed>` and (2) Read on thread `<unnamed>` at alloc218679. (2) just happened here
|
help: and (1) occurred earlier here
--> src/cht/map/bucket_array_ref.rs:308:58
|
308 | maybe_new_bucket_array.unwrap_or_else(|| Owned::new(BucketArray::default()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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):
= note: inside `<cht::map::bucket::BucketArray<i32, i32> as crossbeam_epoch::Pointable>::deref::<'_>` at /Users/parker.timmerman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.15/src/atomic.rs:204:9: 204:28
= note: inside `crossbeam_epoch::Shared::<'_, cht::map::bucket::BucketArray<i32, i32>>::as_ref` at /Users/parker.timmerman/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.15/src/atomic.rs:1518:18: 1518:31
note: inside `cht::map::bucket_array_ref::BucketArrayRef::<'_, i32, i32, std::collections::hash_map::RandomState>::get`
--> src/cht/map/bucket_array_ref.rs:303:54
|
303 | if let Some(bucket_array_ref) = unsafe { bucket_array_ptr.as_ref() } {
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `cht::map::bucket_array_ref::BucketArrayRef::<'_, i32, i32, std::collections::hash_map::RandomState>::insert_with_or_modify_entry_and::<i32, [closure@src/cht/segment.rs:310:17: 310:19], [closure@src/cht/segment.rs:311:17: 311:24], [closure@src/cht/segment.rs:829:77: 829:83]>`
--> src/cht/map/bucket_array_ref.rs:207:27
|
207 | let current_ref = self.get(guard);
| ^^^^^^^^^^^^^^^
note: inside `cht::segment::HashMap::<i32, i32>::insert_entry_and::<i32, [closure@src/cht/segment.rs:829:77: 829:83]>`
--> src/cht/segment.rs:304:22
|
304 | let result = self
| ______________________^
305 | | .bucket_array_ref(hash)
306 | | // .insert_entry_and(key, hash, value, with_previous_entry);
307 | | .insert_with_or_modify_entry_and(
... |
312 | | with_previous_entry,
313 | | );
| |_____________^
note: inside closure
--> src/cht/segment.rs:829:36
|
829 | assert_eq!(map.insert_entry_and(j, map.hash(&j), j, |_, v| *v), None);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^