Don't poison the Mutex when panicking inside Condvar::wait#58461
Don't poison the Mutex when panicking inside Condvar::wait#58461jethrogb wants to merge 1 commit intorust-lang:masterfrom
Conversation
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
4bdb5d3 to
5ebf976
Compare
|
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
The test failure is because the MutexGuard is gone, so during the unwind the unlock isn't happening before the Mutex is dropped. I will modify the PR to fix. |
5ebf976 to
dd20f16
Compare
|
As I mentioned on the other issue, |
|
Note to triage: I will return to this PR March 4. |
|
☔ The latest upstream changes (presumably #58208) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I agree with @alexcrichton here, any panic in |
|
Why is deadlocking an acceptable outcome for a bug in Rust, if we know about the bug and can fix it? The outcome here is neither of those btw. |
|
Can you explain what is causing the panic in the first place? |
|
Doesn't matter, it can be anything. If in |
|
Here's another one. If there's a panic somewhere in use std::{panic, thread, time::Duration};
fn main() {
let _ = panic::catch_unwind(|| {
thread::park_timeout(Duration::from_millis(10));
}); // original panic
let _ = panic::catch_unwind(|| {
thread::park_timeout(Duration::from_millis(10));
}); // “inconsistent park_timeout state”
let _ = panic::catch_unwind(|| {
thread::park_timeout(Duration::from_millis(10));
}); // “PoisonError” (from `thread.inner.lock`)
} |
|
Please continue discussion in #58042 |
Currently, when a panic occurs while a
Condvaris blocking on a wait, this will result in theMutexbeing poisoned, even though the thread that was waiting didn't hold the lock at that time. Various platforms may trigger a panic while a thread is blocked, due to an error condition.This PR changes the
Condvarwait logic so that there is no poison guard on the stack during the wait. It also add a test forCondvar::wait_timeout. It can be tricky to trigger a panic while a thread is blocked. Here I've shimmed pthread_cond_timedwait on Unix systems to trigger an assertion failure in thesyscode.This is similar to but not quite the same as #58042. That issue triggers during any kind of unwinding, this issue only occurs during an actual Rust panic. Therefore, the test can't use
pthread_cancel.r? @alexcrichton