moriturus / ktra

Your Little Cargo Registry
https://book.ktra.dev
Apache License 2.0
405 stars 37 forks source link

Ktra panics when using Mongo db backend #54

Open jbeaurivage opened 2 years ago

jbeaurivage commented 2 years ago

Ktra panics when trying to use the MongoDB driver with Ktra. This seems to stem from an incompatibility between tokio versions (ktra - tokio 1.1, mongodb - tokio 0.2). Here is a backtrace -

Finished dev [unoptimized + debuginfo] target(s) in 1m 32s
     Running `target/debug/ktra --mongodb-url 'mongodb://ktra:password@localhost:27017/'`
thread 'main' panicked at 'there is no timer running, must be called from the context of a Tokio 0.2.x runtime', /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.25/src/time/driver/handle.rs:24:32
stack backtrace:
   0: rust_begin_unwind
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:142:14
   2: core::panicking::panic_display
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:72:5
   3: core::panicking::panic_str
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/panicking.rs:56:5
   4: core::option::expect_failed
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/option.rs:1874:5
   5: core::option::Option<T>::expect
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/option.rs:738:21
   6: tokio::time::driver::handle::Handle::current
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.25/src/time/driver/handle.rs:24:9
   7: tokio::time::driver::registration::Registration::new
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.25/src/time/driver/registration.rs:18:22
   8: tokio::time::delay::Delay::new_timeout
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.25/src/time/delay.rs:72:28
   9: tokio::time::timeout::timeout
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.25/src/time/timeout.rs:53:17
  10: mongodb::runtime::AsyncRuntime::timeout::{{closure}}
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-1.2.5/src/runtime/mod.rs:139:13
  11: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  12: mongodb::sdam::message_manager::TopologyMessageSubscriber::wait_for_message::{{closure}}
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-1.2.5/src/sdam/message_manager.rs:66:55
  13: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  14: mongodb::client::Client::select_server::{{closure}}
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-1.2.5/src/client/mod.rs:280:60
  15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  16: mongodb::client::executor::<impl mongodb::client::Client>::get_session_support_status::{{closure}}
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-1.2.5/src/client/executor.rs:350:76
  17: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  18: mongodb::client::executor::<impl mongodb::client::Client>::start_implicit_session::{{closure}}
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-1.2.5/src/client/executor.rs:326:48
  19: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  20: mongodb::client::executor::<impl mongodb::client::Client>::execute_operation::{{closure}}
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-1.2.5/src/client/executor.rs:48:68
  21: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  22: mongodb::coll::Collection<T>::estimated_document_count::{{closure}}
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/mongodb-1.2.5/src/coll/mod.rs:223:44
  23: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  24: <ktra::db_manager::mongo_db_manager::MongoDbManager as ktra::db_manager::traits::DbManager>::new::{{closure}}::{{closure}}::{{closure}}
             at ./src/db_manager/mongo_db_manager.rs:75:57
  25: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  26: <F as futures_core::future::TryFuture>::try_poll
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-core-0.3.21/src/future.rs:82:9
  27: <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.21/src/future/try_future/into_future.rs:34:9
  28: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.21/src/future/future/map.rs:55:37
  29: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.21/src/lib.rs:91:13
  30: <futures_util::future::try_future::MapErr<Fut,F> as core::future::future::Future>::poll
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.21/src/lib.rs:91:13
  31: <ktra::db_manager::mongo_db_manager::MongoDbManager as ktra::db_manager::traits::DbManager>::new::{{closure}}::{{closure}}
             at ./src/db_manager/mongo_db_manager.rs:89:42
  32: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  33: <ktra::db_manager::mongo_db_manager::MongoDbManager as ktra::db_manager::traits::DbManager>::new::{{closure}}
             at ./src/db_manager/mongo_db_manager.rs:58:5
  34: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  35: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/future.rs:124:9
  36: ktra::run_server::{{closure}}::{{closure}}
             at ./src/main.rs:137:60
  37: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  38: ktra::run_server::{{closure}}
             at ./src/main.rs:107:1
  39: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  40: ktra::main::{{closure}}
             at ./src/main.rs:360:23
  41: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/future/mod.rs:91:19
  42: tokio::park::thread::CachedParkThread::block_on::{{closure}}
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.0/src/park/thread.rs:267:54
  43: tokio::coop::with_budget::{{closure}}
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.0/src/coop.rs:102:9
  44: std::thread::local::LocalKey<T>::try_with
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/thread/local.rs:445:16
  45: std::thread::local::LocalKey<T>::with
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/thread/local.rs:421:9
  46: tokio::coop::with_budget
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.0/src/coop.rs:95:5
  47: tokio::coop::budget
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.0/src/coop.rs:72:5
  48: tokio::park::thread::CachedParkThread::block_on
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.0/src/park/thread.rs:267:31
  49: tokio::runtime::enter::Enter::block_on
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.0/src/runtime/enter.rs:152:13
  50: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.0/src/runtime/scheduler/multi_thread/mod.rs:79:9
  51: tokio::runtime::Runtime::block_on
             at /home/wearable-avionics/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.21.0/src/runtime/mod.rs:492:44
  52: ktra::main
             at ./src/main.rs:360:5
  53: core::ops::function::FnOnce::call_once
             at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
fMeow commented 2 years ago

There is nothing we can do about incompatible async runtime. But in this specific case, I think it can be resolved by upgrading mongodb to 2.0.0 or above, which depends on tokio 1.0

gagbo commented 2 years ago

Our issue here is that we weren't able to make cargo resolve tokio versions somehow. That would have prevented compilation and forced us to find out the issue. But for the time being a bump is probably a good idea. It'll come in 0.7.1, once we sort out the release situation (#52)

jbeaurivage commented 2 years ago

There is nothing we can do about incompatible async runtime. But in this specific case, I think it can be resolved by upgrading mongodb to 2.0.0 or above, which depends on tokio 1.0

I figured as much. I tried upgrading to the latest mongodb in my fork with the intention to submit a PR, but I'm really too unfamiliar with how Mongo works so I didn't manage to make it compile unfortunately.