From 1c1b9c4d1a837c0551afcd271618087738cb0bfa Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Thu, 4 Jun 2026 13:47:48 +0200 Subject: [PATCH] tryfix: reconnect to client on connection error --- record-daemon/src/main.rs | 60 +++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/record-daemon/src/main.rs b/record-daemon/src/main.rs index 3944a0a..495b7fe 100644 --- a/record-daemon/src/main.rs +++ b/record-daemon/src/main.rs @@ -206,16 +206,31 @@ impl Daemon { match watcher.check()? { Some(true) => { - // Client started + // Client started - try to connect info!("League Client detected"); - self.state_machine - .transition(StateTransition::ClientStarted); - + if let Some(creds) = watcher.credentials() { - self.lqp_client.connect(creds.clone()).await?; - self.lqp_client.start_event_listener().await?; - // Start polling for live client events (kills, deaths, objectives) - self.lqp_client.start_live_client_event_poller().await; + match self.lqp_client.connect(creds.clone()).await { + Ok(()) => { + // Only transition to Monitoring after successful connection + self.state_machine + .transition(StateTransition::ClientStarted); + + if let Err(e) = self.lqp_client.start_event_listener().await { + warn!("Failed to start event listener: {}", e); + // Still stay in Monitoring, will retry on next check + } else { + // Start polling for live client events (kills, deaths, objectives) + self.lqp_client.start_live_client_event_poller().await; + } + } + Err(e) => { + warn!("Failed to connect to League Client: {}", e); + // Don't transition to Monitoring - will retry on next check + // The lockfile watcher will return None on next check since + // credentials are already set, so we need to handle reconnection + } + } } } Some(false) => { @@ -225,7 +240,34 @@ impl Daemon { .transition(StateTransition::ClientStopped); self.lqp_client.disconnect().await; } - None => {} + None => { + // No change in lockfile status + // Check if we need to reconnect (lockfile exists but not connected) + if watcher.credentials().is_some() && !self.lqp_client.is_connected().await { + debug!("Lockfile exists but not connected, attempting reconnect..."); + if let Some(creds) = watcher.credentials() { + match self.lqp_client.connect(creds.clone()).await { + Ok(()) => { + // Transition to Monitoring if not already + if !self.state_machine.is_monitoring() { + self.state_machine + .transition(StateTransition::ClientStarted); + } + + if let Err(e) = self.lqp_client.start_event_listener().await { + warn!("Failed to start event listener on reconnect: {}", e); + } else { + self.lqp_client.start_live_client_event_poller().await; + } + } + Err(e) => { + debug!("Reconnect attempt failed: {}", e); + // Will retry on next check + } + } + } + } + } } tokio::time::sleep(poll_interval).await;