@@ -14,7 +14,6 @@ mod version_check;
1414
1515use std:: future:: Future ;
1616
17- use futures:: executor:: block_on;
1817use tonic:: codegen:: InterceptedService ;
1918use tonic:: transport:: { Channel , Uri } ;
2019use 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