Skip to content
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

Error: Thread panicked, must be called from the context of Tokio runtime #2314

Closed
ibraheemdev opened this issue Oct 27, 2020 · 5 comments
Closed

Comments

@ibraheemdev
Copy link

ibraheemdev commented Oct 27, 2020

Running the simple example from hyper.rs:

async fn handle(_: Request<Body>) -> Result<Response<Body>, Infallible> {
    Ok(Response::new("Hello, World!".into()))
}

#[tokio::main]
async fn main() {
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    let make_svc = make_service_fn(|_conn| async {
        Ok::<_, Infallible>(service_fn(handle))
    });
    let server = Server::bind(&addr).serve(make_svc);
    if let Err(e) = server.await {
        eprintln!("server error: {}", e);
    }
}

Causes a panic:

thread 'main' panicked at 'there is no reactor running, must be called from the context of Tokio runtime', /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.22/src/io/driver/mod.rs:202:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Running other examples like mini-redis is totally fine. I suspect this has something to do with the tokio-0.2.22 dependency of h2 and hyper.

Environment

$ rustc -V
=> rustc 1.46.0 (04488afe3 2020-08-24)

OS: macOS Catalina 10.15.7

[dependencies]
hyper = "0.13.8"
tokio = { version = "0.3.1", features = ["full"] }
@ibraheemdev ibraheemdev changed the title Error: thread 'main' panicked at 'there is no reactor running, must be called from the context of Tokio runtime' Error: Thread panicked, must be called from the context of Tokio runtime Oct 27, 2020
@davidbarsky
Copy link
Contributor

I suspect this has something to do with the tokio-0.2.22 dependency of h2 and hyper.

Your hunch is correct. You can work around using Tokio 0.2 or use Tokio 0.3 with tokio-compat-02.

@ibraheemdev
Copy link
Author

ibraheemdev commented Oct 27, 2020

@davidbarsky So hyper is unusable right now with tokio 0.3 until #2302 is complete?

@sfackler
Copy link
Contributor

It is usable with the version of tokio it is developed against.

@davidbarsky
Copy link
Contributor

Hyper 0.13 depends on Tokio 0.2. You can use Hyper 0.13 with Tokio 0.3 if you use the provided compatibility library, tokio-compat-02. If you don't to use tokio-compat-02, you'll need to wait until #2302 is complete.

@ibraheemdev
Copy link
Author

Ok, got it, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants