From fc39e9e740f63843ef302f33868196f1e34f69f9 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Thu, 7 Mar 2024 09:51:56 -0800 Subject: [PATCH] feat: break out of subscription creation loop after 50 attempts --- client/src-tauri/src/telemetry/create_subscription.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/src-tauri/src/telemetry/create_subscription.rs b/client/src-tauri/src/telemetry/create_subscription.rs index 6442707..c9ab0b5 100644 --- a/client/src-tauri/src/telemetry/create_subscription.rs +++ b/client/src-tauri/src/telemetry/create_subscription.rs @@ -14,7 +14,9 @@ use tokio::time::{sleep, Duration}; /// /// This function will retry creating a subscription every 3 seconds /// if it fails. -pub async fn create_subscription(client: &Client) -> Subscription { +pub async fn create_subscription(client: &Client) -> Result { + let mut attempts: u8 = 0; + loop { let subscription_attempt = client .subscribe_w_options( @@ -28,12 +30,17 @@ pub async fn create_subscription(client: &Client) -> Subscription { .await; match subscription_attempt { - Ok(subscription) => break subscription, + Ok(subscription) => break Ok(subscription), Err(e) => { if cfg!(debug_assertions) { println!("Failed to create subscription: {}", e); } + if attempts >= 50 { + break Err(e); + } + + attempts += 1; sleep(Duration::from_secs(3)).await; // Wait for 3 seconds before retrying continue; }