Skip to content

Commit c89c142

Browse files
committed
create dedicated client to avoid 'Service was not ready'
1 parent 1d1c10e commit c89c142

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/qdrant_client/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::{Qdrant, QdrantError};
1616
/// .compression(Some(CompressionEncoding::Gzip))
1717
/// .build();
1818
/// ```
19+
#[derive(Clone)]
1920
pub struct QdrantConfig {
2021
/// Qdrant server URI to connect to
2122
pub uri: String,

src/qdrant_client/mod.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,16 @@ impl Qdrant {
9898
///
9999
/// Constructs the client and connects based on the given [`QdrantConfig`](config::QdrantConfig).
100100
pub fn new(config: QdrantConfig) -> QdrantResult<Self> {
101-
let check_compatibility = config.check_compatibility;
102-
let channel = ChannelPool::new(
103-
config.uri.parse::<Uri>()?,
104-
config.timeout,
105-
config.connect_timeout,
106-
config.keep_alive_while_idle,
107-
);
108-
109-
let client = Self { channel, config };
101+
if config.check_compatibility {
102+
// create a temporary client to check compatibility
103+
let channel = ChannelPool::new(
104+
config.uri.parse::<Uri>()?,
105+
config.timeout,
106+
config.connect_timeout,
107+
config.keep_alive_while_idle,
108+
);
109+
let client = Self { channel, config: config.clone() };
110110

111-
if check_compatibility {
112111
// We're in sync context, spawn temporary runtime in thread to do async health check
113112
let server_version = thread::scope(|s| {
114113
s.spawn(|| {
@@ -120,7 +119,7 @@ impl Qdrant {
120119
.block_on(client.health_check())
121120
})
122121
.join()
123-
.unwrap()
122+
.expect("Failed to join health check thread")
124123
})
125124
.ok()
126125
.map(|info| info.version);
@@ -142,6 +141,15 @@ impl Qdrant {
142141
}
143142
}
144143

144+
let channel = ChannelPool::new(
145+
config.uri.parse::<Uri>()?,
146+
config.timeout,
147+
config.connect_timeout,
148+
config.keep_alive_while_idle,
149+
);
150+
151+
let client = Self { channel, config };
152+
145153
Ok(client)
146154
}
147155

0 commit comments

Comments
 (0)