diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-11-03 20:38:54 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-11-09 10:11:35 +0100 |
| commit | a1b1067d7e8fb30a7cda35ec4e39fcb95f8e7e78 (patch) | |
| tree | 1c7b7b659794e18d21d0cfa016bbd4751e2c75f1 | |
| parent | 43f278edf6e2723caa09c8217211490462bab5d8 (diff) | |
| download | mullvadvpn-a1b1067d7e8fb30a7cda35ec4e39fcb95f8e7e78.tar.xz mullvadvpn-a1b1067d7e8fb30a7cda35ec4e39fcb95f8e7e78.zip | |
Stop relay list updater on shutdown
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 6 | ||||
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 38 |
2 files changed, 10 insertions, 34 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 3bc7b486bc..9d64a67bea 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -735,11 +735,7 @@ where ); // Attempt to download a fresh relay list - let mut relay_handle = relay_selector.updater_handle(); - relay_handle - .update_relay_list_deferred() - .await - .expect("Relay list updated thread has stopped unexpectedly"); + relay_selector.update().await; let mut daemon = Daemon { tunnel_command_tx, diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs index f1f5ec8e9e..45541069f3 100644 --- a/mullvad-daemon/src/relays.rs +++ b/mullvad-daemon/src/relays.rs @@ -224,20 +224,12 @@ impl RelaySelector { } /// Download the newest relay list. - pub fn update(&mut self) -> impl Future<Output = ()> { - let mut updater = self.updater.as_ref().unwrap().clone(); - async move { - updater - .update_relay_list() - .await - .expect("Relay list updated thread has stopped unexpectedly"); + pub async fn update(&self) { + if let Some(mut updater) = self.updater.clone() { + let _ = updater.update_relay_list().await; } } - pub fn updater_handle(&self) -> RelayListUpdaterHandle { - self.updater.as_ref().unwrap().clone() - } - /// Returns all countries and cities. The cities in the object returned does not have any /// relays in them. pub fn get_locations(&mut self) -> RelayList { @@ -992,20 +984,13 @@ impl RelaySelector { #[derive(Clone)] pub struct RelayListUpdaterHandle { - tx: mpsc::Sender<bool>, + tx: mpsc::Sender<()>, } impl RelayListUpdaterHandle { pub async fn update_relay_list(&mut self) -> Result<(), Error> { self.tx - .send(false) - .await - .map_err(|_| Error::DownloaderShutDown) - } - - pub async fn update_relay_list_deferred(&mut self) -> Result<(), Error> { - self.tx - .send(true) + .send(()) .await .map_err(|_| Error::DownloaderShutDown) } @@ -1045,7 +1030,7 @@ impl RelayListUpdater { RelayListUpdaterHandle { tx } } - async fn run(mut self, mut cmd_rx: mpsc::Receiver<bool>) { + async fn run(mut self, mut cmd_rx: mpsc::Receiver<()>) { let mut check_interval = tokio_stream::wrappers::IntervalStream::new(tokio::time::interval_at( (Instant::now() + UPDATE_CHECK_INTERVAL).into(), @@ -1070,17 +1055,12 @@ impl RelayListUpdater { cmd = cmd_rx.next() => { match cmd { - Some(defer) => { + Some(()) => { let tag = self.parsed_relays.lock().tag().map(|tag| tag.to_string()); - if defer { - let download_future = Self::download_relay_list(self.api_availability.clone(), self.rpc_client.clone(), tag); - self.consume_new_relay_list(download_future.await).await; - } else { - self.consume_new_relay_list(self.rpc_client.relay_list(tag).await.map_err(mullvad_rpc::Error::from)).await; - } + download_future = Box::pin(Self::download_relay_list(self.api_availability.clone(), self.rpc_client.clone(), tag).fuse()); }, None => { - log::error!("Relay list updater shutting down"); + log::trace!("Relay list updater shutting down"); return; } } |
