From 5c65a94c138265cb107ecf46bacdd77f8d4141bf Mon Sep 17 00:00:00 2001 From: daywalker90 Date: Sat, 8 Aug 2026 15:01:17 +0200 Subject: [PATCH] add retry logic for hold server connect --- src/main.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index f80d21a..c8136fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -285,11 +285,30 @@ async fn check_hold_support(plugin: Plugin) -> Result<(), anyhow::E .identity(identity) .domain_name("hold"); - let hold_channel = Endpoint::from_shared(format!("https://{hold_grpc_host}:{hold_grpc_port}"))? + let endpoint = Endpoint::from_shared(format!("https://{hold_grpc_host}:{hold_grpc_port}"))? .tls_config(tls_config)? .keep_alive_while_idle(true) - .connect_lazy(); - *plugin.state().hold_client.lock() = Some(HoldClient::new(hold_channel)); + .connect_timeout(Duration::from_secs(5)); + + let max_retries = 20; + + let channel = loop { + match endpoint.connect().await { + Ok(channel) => break channel, + Err(e) if retries < max_retries => { + retries += 1; + + log::debug!("Hold gRPC server not ready, retrying ({retries}/{max_retries}): {e}"); + + time::sleep(Duration::from_millis(500)).await; + } + Err(e) => { + return Err(anyhow!("Hold gRPC server did not become ready: {e}")); + } + } + }; + + *plugin.state().hold_client.lock() = Some(HoldClient::new(channel)); Ok(()) }