pierresouchay / consul-rust

Rust client libray for Consul HTTP API
Apache License 2.0
93 stars 48 forks source link

Cannot drop a runtime in a context where blocking is not allowed when initial consul in rust #65

Open jiangxiaoqiang opened 3 years ago

jiangxiaoqiang commented 3 years ago

I tried to regitstry my rust app into consul using consul rust, first I add dependencies in Cargo.toml:

consul = "0.4.2"

this is my rust code tried to registry app into consul look like:

#[launch]
fn rocket() -> _ {
    let config = Config::new_from_env().unwrap();

}

then I added the env config into .env file in the root of my project:

CONSUL_HTTP_ADDR=consul-1630121482-headless.reddwarf-pro.svc.cluster.local:8500
CONSUL_HTTP_TOKEN="a"

finnaly I start the app using cargo run, shows error like this:

thread 'main' panicked at 'Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context.', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.10.1/src/runtime/blocking/shutdown.rs:51:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

what should I do fix this problem?

jmgilman commented 3 years ago

This issue is a little old - but the problem is this crate is synchronous and tokio is complaining that you're attempting to call a synchronous (blocking) piece of code in an asynchronous context.