From ae369c8a5f94cc00608b2b8d7932c08d2b3bb2c6 Mon Sep 17 00:00:00 2001 From: eladyn Date: Fri, 17 Mar 2023 04:14:44 +0100 Subject: [PATCH] fix reconnection for invalid sessions --- src/main.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index e4727ba8e..48edf1c95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1662,7 +1662,7 @@ async fn main() { let mut connecting = false; let mut _event_handler: Option = None; - let session = Session::new(setup.session_config.clone(), setup.cache.clone()); + let mut session = Session::new(setup.session_config.clone(), setup.cache.clone()); if setup.enable_discovery { let device_id = setup.session_config.device_id.clone(); @@ -1721,6 +1721,10 @@ async fn main() { } }, _ = async {}, if connecting && last_credentials.is_some() => { + if session.is_invalid() { + session = Session::new(setup.session_config.clone(), setup.cache.clone()); + } + let mixer_config = setup.mixer_config.clone(); let mixer = (setup.mixer)(mixer_config); let player_config = setup.player_config.clone(); @@ -1770,15 +1774,12 @@ async fn main() { auto_connect_times.len() > RECONNECT_RATE_LIMIT }; - match last_credentials.clone() { - Some(_) if !reconnect_exceeds_rate_limit() => { - auto_connect_times.push(Instant::now()); - connecting = true; - }, - _ => { - error!("Spirc shut down too often. Not reconnecting automatically."); - exit(1); - }, + if last_credentials.is_some() && !reconnect_exceeds_rate_limit() { + auto_connect_times.push(Instant::now()); + connecting = true; + } else { + error!("Spirc shut down too often. Not reconnecting automatically."); + exit(1); } }, _ = tokio::signal::ctrl_c() => {