diff options
| author | Emīls <emils@mullvad.net> | 2022-02-15 15:21:14 +0000 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2022-02-15 15:21:14 +0000 |
| commit | e0107f9b07bd4d06c59966cb0f30697a7fc71641 (patch) | |
| tree | e2a3c08b8bf51fc6f0d81836fcc6908e8896a168 | |
| parent | 4f1cf5b6a032de6715c026995cc1818acb69d579 (diff) | |
| parent | a65963f515d543e5e3b00ba9e223d1c3463e01fe (diff) | |
| download | mullvadvpn-e0107f9b07bd4d06c59966cb0f30697a7fc71641.tar.xz mullvadvpn-e0107f9b07bd4d06c59966cb0f30697a7fc71641.zip | |
Merge branch 'log-api-availability'
| -rw-r--r-- | mullvad-daemon/src/relays/updater.rs | 15 | ||||
| -rw-r--r-- | mullvad-daemon/src/wireguard.rs | 1 | ||||
| -rw-r--r-- | mullvad-rpc/src/availability.rs | 9 | ||||
| -rw-r--r-- | talpid-core/Cargo.toml | 1 | ||||
| -rw-r--r-- | talpid-core/src/future_retry.rs | 23 |
5 files changed, 41 insertions, 8 deletions
diff --git a/mullvad-daemon/src/relays/updater.rs b/mullvad-daemon/src/relays/updater.rs index 521eee3cda..0c06beb43f 100644 --- a/mullvad-daemon/src/relays/updater.rs +++ b/mullvad-daemon/src/relays/updater.rs @@ -75,16 +75,16 @@ impl RelayListUpdater { } 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(), - UPDATE_CHECK_INTERVAL, - )) - .fuse(); + let mut check_interval = tokio::time::interval_at( + (Instant::now() + UPDATE_CHECK_INTERVAL).into(), + UPDATE_CHECK_INTERVAL, + ); + check_interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip); + let mut ticker = tokio_stream::wrappers::IntervalStream::new(check_interval).fuse(); let mut download_future = Box::pin(Fuse::terminated()); loop { futures::select! { - _check_update = check_interval.next() => { + _check_update = ticker.select_next_some() => { if download_future.is_terminated() && self.should_update() { let tag = self.parsed_relays.lock().tag().map(|tag| tag.to_string()); download_future = Box::pin(Self::download_relay_list(self.api_availability.clone(), self.rpc_client.clone(), tag).fuse()); @@ -94,7 +94,6 @@ impl RelayListUpdater { new_relay_list = download_future => { self.consume_new_relay_list(new_relay_list).await; - }, cmd = cmd_rx.next() => { diff --git a/mullvad-daemon/src/wireguard.rs b/mullvad-daemon/src/wireguard.rs index e363a2d3dc..eb198b858b 100644 --- a/mullvad-daemon/src/wireguard.rs +++ b/mullvad-daemon/src/wireguard.rs @@ -354,6 +354,7 @@ impl KeyManager { async fn wait_for_key_expiry(key: &PublicKey, rotation_interval_secs: u64) { let mut interval = tokio::time::interval(KEY_CHECK_INTERVAL); + interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip); loop { interval.tick().await; if (Utc::now().signed_duration_since(key.created)).num_seconds() as u64 diff --git a/mullvad-rpc/src/availability.rs b/mullvad-rpc/src/availability.rs index 67eccc3a72..da8d624e80 100644 --- a/mullvad-rpc/src/availability.rs +++ b/mullvad-rpc/src/availability.rs @@ -66,6 +66,7 @@ pub struct ApiAvailabilityHandle { impl ApiAvailabilityHandle { pub fn suspend(&self) { + log::debug!("Suspending API requests"); let mut state = self.state.lock().unwrap(); if !state.suspended { state.suspended = true; @@ -74,6 +75,7 @@ impl ApiAvailabilityHandle { } pub fn unsuspend(&self) { + log::debug!("Unsuspending API requests"); let mut state = self.state.lock().unwrap(); if state.suspended { state.suspended = false; @@ -82,6 +84,7 @@ impl ApiAvailabilityHandle { } pub fn pause_background(&self) { + log::debug!("Pausing background API requests"); let mut state = self.state.lock().unwrap(); if !state.pause_background { state.pause_background = true; @@ -90,6 +93,7 @@ impl ApiAvailabilityHandle { } pub fn resume_background(&self) { + log::debug!("Resuming background API requests"); let mut state = self.state.lock().unwrap(); if state.pause_background { state.pause_background = false; @@ -98,6 +102,11 @@ impl ApiAvailabilityHandle { } pub fn set_offline(&self, offline: bool) { + if offline { + log::debug!("Pausing API requests due to being offline"); + } else { + log::debug!("Resuming API requests due to coming online"); + } let mut state = self.state.lock().unwrap(); if state.offline != offline { state.offline = offline; diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml index 9ad5a2ab33..8b55f3524a 100644 --- a/talpid-core/Cargo.toml +++ b/talpid-core/Cargo.toml @@ -91,3 +91,4 @@ tonic-build = { version = "0.5", default-features = false, features = ["transpor tempfile = "3.0" quickcheck = "1.0" quickcheck_macros = "1.0" +tokio = { version = "1", features = [ "test-util" ] } diff --git a/talpid-core/src/future_retry.rs b/talpid-core/src/future_retry.rs index 641babac33..37937e173a 100644 --- a/talpid-core/src/future_retry.rs +++ b/talpid-core/src/future_retry.rs @@ -205,4 +205,27 @@ mod test { let jittered_duration = apply_jitter(unjittered_duration, jitter); assert!(jittered_duration <= unjittered_duration); } + + #[tokio::test] + async fn test_exponential_backoff_delay() { + let retry_interval_initial = Duration::from_secs(4); + let retry_interval_factor = 5; + let retry_interval_max = Duration::from_secs(24 * 60 * 60); + tokio::time::pause(); + + let _ = retry_future_n( + || async { 0 }, + |_| true, + ExponentialBackoff::new(retry_interval_initial, retry_interval_factor) + .max_delay(retry_interval_max), + 5, + ) + .await; + } + + #[tokio::test] + async fn test_timer_advancement() { + tokio::time::pause(); + sleep(Duration::from_secs(60 * 60)).await + } } |
