tokio-rs / loom

Concurrency permutation testing tool for Rust.
MIT License
2.13k stars 111 forks source link

Loom threads cause a panic inside panic in raw_yield #275

Closed kvark closed 2 years ago

kvark commented 2 years ago
* thread #3, name = 'overflow', stop reason = breakpoint 1.1
  * frame #0: 0x0000000100271c07 synqueue-58661dcdb8b1d772`rust_panic at panicking.rs:746:9 [opt]
    frame #1: 0x0000000100271986 synqueue-58661dcdb8b1d772`std::panicking::rust_panic_with_hook::ha581a2c99399f83b at panicking.rs:716:5 [opt]
    frame #2: 0x00000001000345b7 synqueue-58661dcdb8b1d772`std::panicking::begin_panic::_$u7b$$u7b$closure$u7d$$u7d$::h91699f5bb5d1ed4f at panicking.rs:617:9
    frame #3: 0x000000010004ceaa synqueue-58661dcdb8b1d772`std::sys_common::backtrace::__rust_end_short_backtrace::h12cba6f7805167fb(f={closure_env#0}<generator::rt::Error> @ 0x0000000100aad960) at backtrace.rs:138:18
    frame #4: 0x0000000100294013 synqueue-58661dcdb8b1d772`std::panicking::begin_panic::h50f1c57bfc56b21c(msg=Cancel) at panicking.rs:616:12
    frame #5: 0x00000001000504d3 synqueue-58661dcdb8b1d772`generator::yield_::raw_yield::hb1a22b413d687021(env=0x0000000100aada70, context=0x0000000100aadee0, v=<unavailable>) at yield_.rs:60:9
    frame #6: 0x00000001000503a5 synqueue-58661dcdb8b1d772`generator::yield_::yield_::h5bc204320e67d353(v=<unavailable>) at yield_.rs:104:5
    frame #7: 0x000000010004b6e5 synqueue-58661dcdb8b1d772`loom::rt::scheduler::spawn_threads::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hd14c77fd3cdf62b8((null)={closure_env#0} @ 0x0000000100aadaf8) at scheduler.rs:147:56
    frame #8: 0x0000000100041f8d synqueue-58661dcdb8b1d772`generator::gen_impl::GeneratorImpl$LT$A$C$T$GT$::init_code::_$u7b$$u7b$closure$u7d$$u7d$::hbf9e8eb4558a1fb3 at gen_impl.rs:348:21
    frame #9: 0x0000000100060136 synqueue-58661dcdb8b1d772`generator::stack::StackBox$LT$F$GT$::call_once::hf8ec58e2ae8f7b90(data=0x0000000100aade80) at mod.rs:139:13
    frame #10: 0x00000001001f93bf synqueue-58661dcdb8b1d772`generator::stack::Func::call_once::hc3d3b3093ab29879(self=Func @ 0x0000000100aadc68) at mod.rs:121:9
    frame #11: 0x00000001001fca04 synqueue-58661dcdb8b1d772`generator::gen_impl::gen_init::_$u7b$$u7b$closure$u7d$$u7d$::h6f94a749a070dd6a at gen_impl.rs:550:9
    frame #12: 0x00000001001fa895 synqueue-58661dcdb8b1d772`core::ops::function::FnOnce::call_once::hcc543b6fa1515614((null)={closure_env#0} @ 0x0000000100aadcb0, (null)=<unavailable>) at function.rs:227:5
    frame #13: 0x00000001001fc04a synqueue-58661dcdb8b1d772`std::panicking::try::do_call::h1869a8b18ebb14c5(data="\xa0ߪ") at panicking.rs:492:40
    frame #14: 0x00000001001fc32d synqueue-58661dcdb8b1d772`__rust_try + 29
    frame #15: 0x00000001001fbfc2 synqueue-58661dcdb8b1d772`std::panicking::try::he719f8c3ae29252d(f={closure_env#0} @ 0x0000000100aadd98) at panicking.rs:456:19
    frame #16: 0x00000001001fa481 synqueue-58661dcdb8b1d772`std::panic::catch_unwind::h074a6d46fc2c7d48(f={closure_env#0} @ 0x0000000100aaddf8) at panic.rs:137:14
    frame #17: 0x00000001001fc925 synqueue-58661dcdb8b1d772`generator::gen_impl::gen_init::hd7515d702382bd47((null)=0, f=0x0000000100aadfa0) at gen_impl.rs:564:25
(lldb) f 6
frame #6: 0x00000001000503a5 synqueue-58661dcdb8b1d772`generator::yield_::yield_::h5bc204320e67d353(v=<unavailable>) at yield_.rs:104:5
   101  pub fn yield_<A: Any, T: Any>(v: T) -> Option<A> {
   102      let env = ContextStack::current();
   103      let context = env.top();
-> 104      raw_yield(&env, context, v);
   105      atomic::compiler_fence(atomic::Ordering::Acquire);
   106      raw_get_yield(context)
   107  }
(lldb) f 5
frame #5: 0x00000001000504d3 synqueue-58661dcdb8b1d772`generator::yield_::raw_yield::hb1a22b413d687021(env=0x0000000100aada70, context=0x0000000100aadee0, v=<unavailable>) at yield_.rs:60:9
   57   
   58       // here we just panic to exit the func
   59       if context._ref != 1 {
-> 60           panic!(Error::Cancel);
   61       }
   62   }
   63   

Repro:

git clone https://github.com/kvark/synqueue
cd synqueue
git checkout 16a38c4d42e267b153d6961c041536fa93e0cb3a
cargo test --features loom
kvark commented 2 years ago

Yes, what could possibly be wrong:

#[cfg(not(feature = "loom"))]
use std::{
    cell::UnsafeCell,
    hint,
    sync::atomic::{AtomicUsize, Ordering},
};
#[cfg(feature = "loom")]
use std::{
    cell::UnsafeCell,
    hint,
    sync::atomic::{AtomicUsize, Ordering},
};

Sorry about the noise!