-
Notifications
You must be signed in to change notification settings - Fork 360
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
Print out both accesses involved in a data race #2205
Comments
Stacked Borrows recently got some support for showing extra spans thanks to @saethlin; we probably want to reuse that -- in particular it doesn't use Also, augmenting every timestamp might be a bit too expensive in terms of performance? |
I don't know that augmenting every timestamp would be too slow. TSan manages to report backtraces in a debug build for these races, and those backtraces are not small and we're only trying to report one measly span. If someone is interested in doing this, it's probably worth giving the naïve approach a shot. If it's too slow I already have some ideas. |
Is there a way to get a backtrace in Miri, and how expensive would this be? Only showing one span is probably not too helpful |
Lines 825 to 860 in dcaa7a7
|
@saethlin Thanks, that looks handy.
I realised what I said wouldn't work, because miri/src/concurrency/data_race.rs Lines 32 to 36 in dcaa7a7
On a data race, we know the offending timestamp, but that could cover multiple spans so we won't be able to pinpoint a line |
I was trying to debug a data race in https://github.com/ibraheemdev/seize and had it narrowed down to a simple test case with two threads. I wanted to see the order in which miri was interleaving the threads to narrow down the bug, but adding debug statements added extra synchronization that fixed the data race ;) I ended up having to use a thread-unsafe pub fn println(x: String) {
unsafe {
let mut f = std::fs::File::from_raw_fd(1);
f.write_all(x.as_bytes()).unwrap();
std::mem::forget(f);
}
} And I did manage to find the missing synchronization edge, but it would be nice if this was easier. |
We could give each timestamp a start and end span. I wonder how many times when we report a diagnostic the start and end span would be the same. |
Data race spans Fixes rust-lang/miri#2205 This adds output to data race errors very similar to the spans we emit for Stacked Borrows errors. For example, from our test suite: ``` help: The Atomic Load on thread `<unnamed>` is here --> tests/fail/data_race/atomic_read_na_write_race1.rs:23:13 | 23 | ... (&*c.0).load(Ordering::SeqCst) //~ ERROR: Data race detected between Atomic Load on thread `<unnamed>` and Write o... | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: The Write on thread `<unnamed>` is here --> tests/fail/data_race/atomic_read_na_write_race1.rs:19:13 | 19 | *(c.0 as *mut usize) = 32; | ^^^^^^^^^^^^^^^^^^^^^^^^^``` ``` Because of rust-lang/miri#2647 this comes without a perf regression, according to our benchmarks.
Currently Miri throws a UB on the access that ultimately causes a data race, which is always the later one. It is not clear where the other access involved in the data race is in the source file.
Both TSan and Go's race detector print out the line numbers of both accesses involved in the data race, we'd like to do the same.
It shouldn't be too hard to implement, we just need to augment
VTimestamp
with the currentSpan
fromMiriEvalContext::cur_span()
miri/src/vector_clock.rs
Line 45 in aca3b3a
The text was updated successfully, but these errors were encountered: