@@ -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<Status>, watch::Receiver<Status>),
entity_id_extractors: HashMap<TypeId, fn(&dyn AnyTypedEnvelope) -> u64>,
_reconnect_task: Option<Task<()>>,
- reconnect_interval: Duration,
entities_by_type_and_remote_id: HashMap<(TypeId, u64), WeakSubscriber>,
models_by_message_type: HashMap<TypeId, AnyWeakModel>,
entity_types_by_message_type: HashMap<TypeId, TypeId>,
@@ -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;
}