coio-rs icon indicating copy to clipboard operation
coio-rs copied to clipboard

[FATAL] Yield coroutines while stack unwinding causes panic while panicking

Open zonyitoo opened this issue 5 years ago • 2 comments

Reproducible example:

extern crate coio;
extern crate env_logger;

use coio::Scheduler;

fn main() {
    env_logger::init();

    Scheduler::new()
        .run(|| {
            struct A;

            impl Drop for A {
                fn drop(&mut self) {
                    Scheduler::sched();
                }
            }

            let _a = A;

            panic!("PANICKED in coroutine");
        }).unwrap();
}

While the coroutine is unwinding, Drop of A will be called. Coroutine is yield in the drop() function. Coroutine is now suspended, which means that the currently thread is still in panicking status, but execution process is now be switched to another coroutine. If the other coroutine panic, too, then it will definitely cause panic while panicking!.

zonyitoo avatar Aug 26 '18 02:08 zonyitoo

cc @lhecker , this is the root cause.

zonyitoo avatar Aug 26 '18 02:08 zonyitoo

@zonyitoo Yup that's basically why we asked the Rust devs to reconsider and stop using TLS for panics in the stdlib back then when we worked on coio. Since they denied my PR and basically said that it's unlikely even for an RFC to change this behaviour I think this might be a dead end for the project. 😕 (Unless you fork the stdlib of course.)

lhecker avatar Aug 26 '18 10:08 lhecker