summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2023-10-21 15:06:54 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-10-30 23:15:25 +0100
commit047e542f513ec05489200d8731a9bc7045854719 (patch)
tree07a50dbd0e92e0668747c04d7f844b3445c9fbd0
parent8dd49b1e9643ba0aecd414f2d544c5190a38e530 (diff)
downloadmullvadvpn-047e542f513ec05489200d8731a9bc7045854719.tar.xz
mullvadvpn-047e542f513ec05489200d8731a9bc7045854719.zip
Wait for unsuspend
-rw-r--r--mullvad-api/src/rest.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/mullvad-api/src/rest.rs b/mullvad-api/src/rest.rs
index de6635b0b1..1a1b2439c8 100644
--- a/mullvad-api/src/rest.rs
+++ b/mullvad-api/src/rest.rs
@@ -230,7 +230,7 @@ impl<
let tx = self.command_tx.upgrade();
let api_availability = self.api_availability.clone();
- let request_future = request.into_future(self.client.clone());
+ let request_future = request.into_future(self.client.clone(), api_availability.clone());
tokio::spawn(async move {
let response = request_future.await.map_err(|error| error.map_aborted());
@@ -373,9 +373,24 @@ impl Request {
}
async fn into_future<C: Connect + Clone + Send + Sync + 'static>(
+ self,
+ hyper_client: hyper::Client<C>,
+ api_availability: ApiAvailabilityHandle,
+ ) -> Result<Response> {
+ let timeout = self.timeout;
+ let inner_fut = self.into_future_without_timeout(hyper_client, api_availability);
+ tokio::time::timeout(timeout, inner_fut)
+ .await
+ .map_err(|_| Error::TimeoutError)?
+ }
+
+ async fn into_future_without_timeout<C: Connect + Clone + Send + Sync + 'static>(
mut self,
hyper_client: hyper::Client<C>,
+ api_availability: ApiAvailabilityHandle,
) -> Result<Response> {
+ let _ = api_availability.wait_for_unsuspend().await;
+
// Obtain access token first
if let (Some(account), Some(store)) = (&self.account, &self.access_token_store) {
let access_token = store.get_token(account).await?;
@@ -387,10 +402,9 @@ impl Request {
}
// Make request to hyper client
- let request_fut = hyper_client.request(self.request);
- let response = tokio::time::timeout(self.timeout, request_fut)
+ let response = hyper_client
+ .request(self.request)
.await
- .map_err(|_| Error::TimeoutError)?
.map_err(Error::from);
// Notify access token store of expired tokens