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
This commit is contained in:
Max Brunsfeld 2024-05-28 12:42:10 -07:00 committed by GitHub
parent da70741ece
commit 726026a267
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -84,7 +84,8 @@ lazy_static! {
std::env::var("ZED_ALWAYS_ACTIVE").map_or(false, |e| !e.is_empty()); 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); pub const CONNECTION_TIMEOUT: Duration = Duration::from_secs(20);
actions!(client, [SignIn, SignOut, Reconnect]); actions!(client, [SignIn, SignOut, Reconnect]);
@ -287,7 +288,6 @@ struct ClientState {
status: (watch::Sender<Status>, watch::Receiver<Status>), status: (watch::Sender<Status>, watch::Receiver<Status>),
entity_id_extractors: HashMap<TypeId, fn(&dyn AnyTypedEnvelope) -> u64>, entity_id_extractors: HashMap<TypeId, fn(&dyn AnyTypedEnvelope) -> u64>,
_reconnect_task: Option<Task<()>>, _reconnect_task: Option<Task<()>>,
reconnect_interval: Duration,
entities_by_type_and_remote_id: HashMap<(TypeId, u64), WeakSubscriber>, entities_by_type_and_remote_id: HashMap<(TypeId, u64), WeakSubscriber>,
models_by_message_type: HashMap<TypeId, AnyWeakModel>, models_by_message_type: HashMap<TypeId, AnyWeakModel>,
entity_types_by_message_type: HashMap<TypeId, TypeId>, entity_types_by_message_type: HashMap<TypeId, TypeId>,
@ -363,7 +363,6 @@ impl Default for ClientState {
status: watch::channel_with(Status::SignedOut), status: watch::channel_with(Status::SignedOut),
entity_id_extractors: Default::default(), entity_id_extractors: Default::default(),
_reconnect_task: None, _reconnect_task: None,
reconnect_interval: Duration::from_secs(5),
models_by_message_type: Default::default(), models_by_message_type: Default::default(),
entities_by_type_and_remote_id: Default::default(), entities_by_type_and_remote_id: Default::default(),
entity_types_by_message_type: Default::default(), entity_types_by_message_type: Default::default(),
@ -623,7 +622,6 @@ impl Client {
} }
Status::ConnectionLost => { Status::ConnectionLost => {
let this = self.clone(); let this = self.clone();
let reconnect_interval = state.reconnect_interval;
state._reconnect_task = Some(cx.spawn(move |cx| async move { state._reconnect_task = Some(cx.spawn(move |cx| async move {
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
let mut rng = StdRng::seed_from_u64(0); let mut rng = StdRng::seed_from_u64(0);
@ -642,8 +640,9 @@ impl Client {
); );
cx.background_executor().timer(delay).await; cx.background_executor().timer(delay).await;
delay = delay delay = delay
.mul_f32(rng.gen_range(1.0..=2.0)) .mul_f32(rng.gen_range(0.5..=2.5))
.min(reconnect_interval); .max(INITIAL_RECONNECTION_DELAY)
.min(MAX_RECONNECTION_DELAY);
} else { } else {
break; break;
} }