Skip to content

Commit 1d1c10e

Browse files
committed
Check compatibility in temporary thread
1 parent 3b53ff7 commit 1d1c10e

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/qdrant_client/mod.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod snapshot;
1313
mod version_check;
1414

1515
use std::future::Future;
16+
use std::thread;
1617

1718
use tonic::codegen::InterceptedService;
1819
use tonic::transport::{Channel, Uri};
@@ -108,16 +109,21 @@ impl Qdrant {
108109
let client = Self { channel, config };
109110

110111
if check_compatibility {
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),
119-
};
120-
let server_version = server_version.map(|info| info.version).ok();
112+
// We're in sync context, spawn temporary runtime in thread to do async health check
113+
let server_version = thread::scope(|s| {
114+
s.spawn(|| {
115+
tokio::runtime::Builder::new_current_thread()
116+
.enable_io()
117+
.enable_time()
118+
.build()
119+
.map_err(QdrantError::Io)?
120+
.block_on(client.health_check())
121+
})
122+
.join()
123+
.unwrap()
124+
})
125+
.ok()
126+
.map(|info| info.version);
121127

122128
let client_version = env!("CARGO_PKG_VERSION").to_string();
123129
if let Some(server_version) = server_version {

0 commit comments

Comments
 (0)