thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
324 stars 40 forks source link

thread 'main' panicked at 'there is no timer running, must be called from the context of a Tokio 0.2.x runtime' #100

Closed Lucyfurnice closed 1 year ago

Lucyfurnice commented 1 year ago

When I include code in my main that syncs a model, or within a function that main calls, I get a huge stacktrace. thread 'main' panicked at 'there is no timer running, must be called from the context of a Tokio 0.2.x runtime'... I see there is an old issue on mongodb-rust-driver but i could not try because of version changes.

main

async fn main() -> Result<(), Box> { ... let db_client:Client = create_db_client().await.unwrap(); let db:Database = db_client.database("name"); Topic::sync(db).await; ... }

Cargo.toml

[dependencies] clap = { version = "4.2.1", features = ["derive"] } clokwerk = "0.4.0" dptree = "0.3.0" fern = { version = "0.6.2", features = ["date-based", "chrono", "colored"] } futures = "0.3.28" humantime = "2.1.0" log = { version = "0.4.17", features = ["serde"] } reqwest = { version = "0.11.16", features = ["tokio-socks", "serde_json", "json", "gzip", "deflate", "cookies", "cookie_store"] } rss = { version = "2.0.3", features = ["serde", "chrono", "atom", "with-serde", "validation"] } selectors = { version = "0.24.0", features= [] } serde = { version = "1.0.159", features = ["derive"] } serde_json = { version = "1.0.95", features = ["preserve_order"] } teloxide = { version = "0.12.2", features = ["webhooks", "macros", "throttle", "sqlite-storage"] } tokio = { version = "1.27.0", features = ["bytes", "net", "rt-multi-thread", "time", "process", "macros", "sync", "signal", "fs", "windows-sys", "stats", "io-std", "io-util"] } wither = { version = "0.9.0" , features = [] }

Lucyfurnice commented 1 year ago

I did find that mongo-rust-driver is using tokio version = "1.17.0" I guess that would be the problem

C:\Repositories\git.debased.earth\zhb\cassius>.\target\debug\cassius.exe thread 'main' panicked at 'there is no timer running, must be called from the context of a Tokio 0.2.x runtime', C:\Users\Lucyfurnice\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.25\src\time\driver\handle.rs:24:32 stack backtrace: ...

Lucyfurnice commented 1 year ago

I think my feature flags could be conflicting let me try to compile the tutorial.

cargo new mongotest cd mongotest cargo add tokio --features full cargo add wither --features tokio-runtime cargo add futures cargo add serde

https://github.com/thedodd/wither/blob/master/wither/examples/readme.rs as the source in main.rs

cargo build .\target\debug\mongotest.exe

thread 'main' panicked at 'there is no timer running, must be called from the context of a Tokio 0.2.x runtime', C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.25\src\time\driver\handle.rs:24:32 stack backtrace: 0: std::panicking::begin_panic_handler at /rustc/8460ca823e8367a30dda430efda790588b8c84d3/library\std\src\panicking.rs:575 1: core::panicking::panic_fmt at /rustc/8460ca823e8367a30dda430efda790588b8c84d3/library\core\src\panicking.rs:64 2: core::panicking::panic_display<ref$<str$> > at /rustc/8460ca823e8367a30dda430efda790588b8c84d3/library\core\src\panicking.rs:147 3: core::panicking::panic_str at /rustc/8460ca823e8367a30dda430efda790588b8c84d3/library\core\src\panicking.rs:131 4: core::option::expect_failed at /rustc/8460ca823e8367a30dda430efda790588b8c84d3/library\core\src\option.rs:1924 5: enum2$<core::option::Option >::expect at /rustc/8460ca823e8367a30dda430efda790588b8c84d3\library\core\src\option.rs:786 6: tokio::time::driver::handle::Handle::current at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.25\src\time\driver\handle.rs:24 7: tokio::time::driver::registration::Registration::new at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.25\src\time\driver\registration.rs:18 8: tokio::time::delay::Delay::new_timeout at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.25\src\time\delay.rs:72 9: tokio::time::timeout::timeout<enum2$<tokio::sync::watch::impl$1::recv::async_fn_env$0<tuple$<> > > > at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.25\src\time\timeout.rs:53 10: mongodb::runtime::impl$0::timeout::async_fn$0<enum2$<tokio::sync::watch::impl$1::recv::async_fn_env$0<tuple$<> > > > at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\mongodb-1.2.5\src\runtime\mod.rs:139 11: mongodb::sdam::message_manager::impl$1::wait_for_message::async_fn$0 at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\mongodb-1.2.5\src\sdam\message_manager.rs:66 12: mongodb::client::impl$1::select_server::async_fn$0 at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\mongodb-1.2.5\src\client\mod.rs:281 13: mongodb::client::executor::impl$0::get_session_support_status::async_fn$0 at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\mongodb-1.2.5\src\client\executor.rs:350 14: mongodb::client::executor::impl$0::start_implicit_session::async_fn$0 at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\mongodb-1.2.5\src\client\executor.rs:326 15: mongodb::client::executor::impl$0::execute_operation::async_fn$0 at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\mongodb-1.2.5\src\client\executor.rs:48 16: mongodb::db::impl$0::run_command::async_fn$0<enum2$<core::option::Option<enum2$ > > > at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\mongodb-1.2.5\src\db\mod.rs:268 17: wither::model::get_current_indexes::async_fn$0 at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\wither-0.9.0\src\model.rs:339 18: wither::model::Model::sync::async_block$0 at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\wither-0.9.0\src\model.rs:325 19: core::future::future::impl$1::poll<alloc::boxed::Box<dyn$<core::future::future::Future<assoc$<Output,enum2$<core::result::Result<tuple$<>,enum2$ > > > >,core::marker::Send>,alloc::alloc::Global> > at /rustc/8460ca823e8367a30dda430efda790588b8c84d3\library\core\src\future\future.rs:125 20: main::main::async_block$0 at .\src\bin\main.rs:22 21: tokio::runtime::park::impl$4::block_on::closure$0<enum2$<main::main::async_block_env$0> > at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.28.0\src\runtime\park.rs:283 22: tokio::runtime::coop::with_budget at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.28.0\src\runtime\coop.rs:107 23: tokio::runtime::coop::budget at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.28.0\src\runtime\coop.rs:73 24: tokio::runtime::park::CachedParkThread::block_on<enum2$<main::main::async_block_env$0> > at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.28.0\src\runtime\park.rs:283 25: tokio::runtime::context::BlockingRegionGuard::block_on<enum2$<main::main::async_block_env$0> > at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.28.0\src\runtime\context.rs:315 26: tokio::runtime::scheduler::multi_thread::MultiThread::block_on<enum2$<main::main::async_block_env$0> > at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.28.0\src\runtime\scheduler\multi_thread\mod.rs:66 27: tokio::runtime::runtime::Runtime::block_on<enum2$<main::main::async_block_env$0> > at C:\Users\Lucyfurnice.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.28.0\src\runtime\runtime.rs:304 28: main::main at .\src\bin\main.rs:33 29: core::ops::function::FnOnce::call_once<enum2$<core::result::Result<tuple$<>,enum2$ > > (*)(),tuple$<> > at /rustc/8460ca823e8367a30dda430efda790588b8c84d3\library\core\src\ops\function.rs:250 note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

Lucyfurnice commented 1 year ago

Switching tokio to version "0.2.25" works. Wonder what is using that version...

Lucyfurnice commented 1 year ago

fixed with cargo add --git [this repo]