mirror of
https://github.com/daywalker90/cln-nip47.git
synced 2026-08-13 12:33:43 +02:00
add retry logic for hold server connect
This commit is contained in:
parent
f5b64586fc
commit
5c65a94c13
1 changed files with 22 additions and 3 deletions
25
src/main.rs
25
src/main.rs
|
|
@ -285,11 +285,30 @@ async fn check_hold_support(plugin: Plugin<PluginState>) -> 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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue