From 726026a267a09b529b4d11b699343b710a3207e9 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 28 May 2024 12:42:10 -0700 Subject: [PATCH] Tweak client reconnect timing (#12393) * Start with a longer duration * Widen the range used for randomizing the duration between retries * Increase the maximum duration between retries Release Notes: - N/A --- crates/client/src/client.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index c9e61a64f3..e9608cd404 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -84,7 +84,8 @@ lazy_static! { std::env::var("ZED_ALWAYS_ACTIVE").map_or(false, |e| !e.is_empty()); } -pub const INITIAL_RECONNECTION_DELAY: Duration = Duration::from_millis(100); +pub const INITIAL_RECONNECTION_DELAY: Duration = Duration::from_millis(500); +pub const MAX_RECONNECTION_DELAY: Duration = Duration::from_secs(10); pub const CONNECTION_TIMEOUT: Duration = Duration::from_secs(20); actions!(client, [SignIn, SignOut, Reconnect]); @@ -287,7 +288,6 @@ struct ClientState { status: (watch::Sender, watch::Receiver), entity_id_extractors: HashMap u64>, _reconnect_task: Option>, - reconnect_interval: Duration, entities_by_type_and_remote_id: HashMap<(TypeId, u64), WeakSubscriber>, models_by_message_type: HashMap, entity_types_by_message_type: HashMap, @@ -363,7 +363,6 @@ impl Default for ClientState { status: watch::channel_with(Status::SignedOut), entity_id_extractors: Default::default(), _reconnect_task: None, - reconnect_interval: Duration::from_secs(5), models_by_message_type: Default::default(), entities_by_type_and_remote_id: Default::default(), entity_types_by_message_type: Default::default(), @@ -623,7 +622,6 @@ impl Client { } Status::ConnectionLost => { let this = self.clone(); - let reconnect_interval = state.reconnect_interval; state._reconnect_task = Some(cx.spawn(move |cx| async move { #[cfg(any(test, feature = "test-support"))] let mut rng = StdRng::seed_from_u64(0); @@ -642,8 +640,9 @@ impl Client { ); cx.background_executor().timer(delay).await; delay = delay - .mul_f32(rng.gen_range(1.0..=2.0)) - .min(reconnect_interval); + .mul_f32(rng.gen_range(0.5..=2.5)) + .max(INITIAL_RECONNECTION_DELAY) + .min(MAX_RECONNECTION_DELAY); } else { break; }