tokio: `tokio::run` doesn't propogate panics from futures

I assumed the following test would fail, but it currently passes.

#[test]
fn my_test() {
    tokio::run(future::lazy(|| -> Result<_, _> {
        panic!("oh no!")
    }))
}

Is this expected behaviour? It doesn’t seem like it should be.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I hate to drag back open an old issue, but this is still a problem. I can’t find a way to reliably capture threadpool panics in tests. I have a codebase liberally using tokio::spawn that I’m in the middle of fuzzing, and certain inputs cause those spawned futures to error or panic. From the standpoint of tokio::spawn there appears to be no behavioral difference between a passed Future returning an err or an ok. I guess this is like being unable to react to panics in a detached thread? What’s the joinable thread alternative, and is it documented somewhere I’m not seeing?