Skip to content

Commit 3b53ff7

Browse files
committed
Do async health check in sync context
1 parent f734d58 commit 3b53ff7

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ serde = { version = "1.0.210", features = ["derive"], optional = true }
2121
serde_json = { version = "1.0.128", optional = true }
2222
reqwest = { version = "0.12.8", optional = true, default-features = false, features = ["stream", "rustls-tls", "http2"] }
2323
futures = { version = "0.3.31" }
24+
tokio = { version = "1.40.0", features = ["rt-multi-thread"] }
2425
futures-util = { version = "0.3.31", optional = true }
2526
derive_builder = { version = "0.20.2" }
2627
thiserror = "1.0.64"
2728

2829
[dev-dependencies]
2930
tonic-build = { version = "0.12.3", features = ["prost"] }
30-
tokio = { version = "1.40.0", features = ["rt-multi-thread"] }
3131

3232
[features]
3333
default = ["download_snapshots", "serde", "generate-snippets"]

src/qdrant_client/mod.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ mod version_check;
1414

1515
use std::future::Future;
1616

17-
use futures::executor::block_on;
1817
use tonic::codegen::InterceptedService;
1918
use tonic::transport::{Channel, Uri};
2019
use tonic::Status;
@@ -109,24 +108,31 @@ impl Qdrant {
109108
let client = Self { channel, config };
110109

111110
if check_compatibility {
112-
let client_version = env!("CARGO_PKG_VERSION").to_string();
113-
let server_version = match block_on(async { client.health_check().await }) {
114-
Ok(server_info) => server_info.version,
115-
Err(_) => "Unknown".to_string(),
111+
let health_check_future = client.health_check();
112+
113+
// Run future on current or new runtime depending on current context
114+
let server_version = match tokio::runtime::Handle::try_current() {
115+
Ok(_) => futures::executor::block_on(health_check_future),
116+
Err(_) => tokio::runtime::Runtime::new()
117+
.unwrap()
118+
.block_on(health_check_future),
116119
};
117-
if server_version == "Unknown" {
118-
println!(
119-
"Failed to obtain server version. \
120-
Unable to check client-server compatibility. \
121-
Set check_compatibility=false to skip version check."
122-
);
123-
} else {
120+
let server_version = server_version.map(|info| info.version).ok();
121+
122+
let client_version = env!("CARGO_PKG_VERSION").to_string();
123+
if let Some(server_version) = server_version {
124124
let is_compatible = is_compatible(Some(&client_version), Some(&server_version));
125125
if !is_compatible {
126126
println!("Client version {client_version} is not compatible with server version {server_version}. \
127127
Major versions should match and minor version difference must not exceed 1. \
128128
Set check_compatibility=false to skip version check.");
129129
}
130+
} else {
131+
println!(
132+
"Failed to obtain server version. \
133+
Unable to check client-server compatibility. \
134+
Set check_compatibility=false to skip version check."
135+
);
130136
}
131137
}
132138

0 commit comments

Comments
 (0)