From 7762741d55fcd8976727ca7837089f2046128082 Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Tue, 27 Aug 2024 14:28:44 -0500 Subject: [PATCH] fix(rust/gui-client): ignore network resets before the tunnel is ready (#6458) Closes #6457 This PR ignores `Session::reset` requests from the GUI while the IPC service is still raising the tunnel. This removes redundant reconnections to the Portal and it may improve behavior on some systems. It's not any faster on my dev laptop. `set_dns` seemed harmless so I didn't touch that. --------- Signed-off-by: Reactor Scram Co-authored-by: Jamil --- rust/headless-client/src/ipc_service.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/rust/headless-client/src/ipc_service.rs b/rust/headless-client/src/ipc_service.rs index f7af80714..bba348e3e 100644 --- a/rust/headless-client/src/ipc_service.rs +++ b/rust/headless-client/src/ipc_service.rs @@ -399,6 +399,10 @@ impl<'a> Handler<'a> { Ok(()) } + fn tunnel_is_ready(&self) -> bool { + self.last_connlib_start_instant.is_none() && self.connlib.is_some() + } + async fn handle_ipc_msg(&mut self, msg: ClientMsg) -> Result<()> { match msg { ClientMsg::ClearLogs => { @@ -433,12 +437,20 @@ impl<'a> Handler<'a> { let filter = spawn_blocking(get_log_filter).await??; self.log_filter_reloader.reload(filter)?; } - ClientMsg::Reset => self.connlib.as_mut().context("No connlib session")?.reset(), - ClientMsg::SetDns(v) => self - .connlib - .as_mut() - .context("No connlib session")? - .set_dns(v), + ClientMsg::Reset => { + if self.tunnel_is_ready() { + self.connlib.as_mut().context("No connlib session")?.reset(); + } else { + tracing::debug!("Ignoring redundant reset"); + } + } + ClientMsg::SetDns(resolvers) => { + tracing::debug!(?resolvers); + self.connlib + .as_mut() + .context("No connlib session")? + .set_dns(resolvers) + } ClientMsg::SetDisabledResources(disabled_resources) => { self.connlib .as_mut()