Skip to content

Commit

Permalink
fix reconnection for invalid sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
eladyn committed Mar 22, 2023
1 parent 03d4cc7 commit ae369c8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ async fn main() {
let mut connecting = false;
let mut _event_handler: Option<EventHandler> = 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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() => {
Expand Down

0 comments on commit ae369c8

Please sign in to comment.