summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-08-17 19:54:57 +0200
committerDavid Lönnhager <david.l@mullvad.net>2020-09-01 14:17:21 +0200
commitbf0e1e1d845e75f67a320d3876a488aa1ef0db18 (patch)
tree24531fcb905249c317f8d26fc9cfedba46bb00a1
parente7dba4be0e2073ab3d723b2c2532e4a31f0d1aa0 (diff)
downloadmullvadvpn-bf0e1e1d845e75f67a320d3876a488aa1ef0db18.tar.xz
mullvadvpn-bf0e1e1d845e75f67a320d3876a488aa1ef0db18.zip
Avoid thread-blocking futures
-rw-r--r--mullvad-daemon/src/lib.rs37
1 files changed, 21 insertions, 16 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index f848af595d..37cfbecf77 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -20,6 +20,7 @@ mod version_check;
use futures::{
channel::{mpsc, oneshot},
+ compat::Future01CompatExt,
executor::BlockingStream,
future::{abortable, AbortHandle, Future},
};
@@ -666,18 +667,18 @@ where
cb();
}
- let shutdown_signal = tokio::time::timeout(
- TUNNEL_STATE_MACHINE_SHUTDOWN_TIMEOUT,
- tunnel_state_machine_shutdown_signal,
- );
-
- match rpc_runtime.runtime().block_on(shutdown_signal) {
- Ok(_) => log::info!("Tunnel state machine shut down"),
- Err(_) => log::error!("Tunnel state machine did not shut down gracefully"),
- }
- mem::drop(rpc_runtime);
-
+ rpc_runtime.runtime().block_on(async {
+ let shutdown_signal = tokio::time::timeout(
+ TUNNEL_STATE_MACHINE_SHUTDOWN_TIMEOUT,
+ tunnel_state_machine_shutdown_signal,
+ );
+ match shutdown_signal.await {
+ Ok(_) => log::info!("Tunnel state machine shut down"),
+ Err(_) => log::error!("Tunnel state machine did not shut down gracefully"),
+ }
+ });
mem::drop(event_listener);
+ mem::drop(rpc_runtime);
}
/// Shuts down the daemon without shutting down the underlying event listener and the shutdown
@@ -1210,7 +1211,8 @@ where
.map_err(|e| {
warn!("Unable to fetch GeoIP location: {}", e.display_chain());
})
- .wait()
+ .compat()
+ .await
}
}
@@ -1258,7 +1260,7 @@ where
});
self.rpc_runtime.runtime().spawn(async {
- if future.wait().is_err() {
+ if future.compat().await.is_err() {
log::error!("Failed to spawn future for creating a new account");
}
});
@@ -1271,7 +1273,10 @@ where
) {
let expiry_old_fut = self.accounts_proxy.get_expiry(account_token);
let rpc_call = async {
- let result = expiry_old_fut.wait().map(|expiry| AccountData { expiry });
+ let result = expiry_old_fut
+ .compat()
+ .await
+ .map(|expiry| AccountData { expiry });
Self::oneshot_send(tx, result, "account data");
};
self.rpc_runtime.runtime().spawn(rpc_call);
@@ -1284,7 +1289,7 @@ where
if let Some(account_token) = self.settings.get_account_token() {
let old_future = self.accounts_proxy.get_www_auth_token(account_token);
let rpc_call = async {
- let result = old_future.wait();
+ let result = old_future.compat().await;
Self::oneshot_send(tx, result, "get_www_auth_token response");
};
self.rpc_runtime.runtime().spawn(rpc_call);
@@ -1299,7 +1304,7 @@ where
if let Some(account_token) = self.settings.get_account_token() {
let old_future = self.accounts_proxy.submit_voucher(account_token, voucher);
let rpc_call = async {
- let result = old_future.wait();
+ let result = old_future.compat().await;
Self::oneshot_send(tx, result, "submit_voucher response");
};
self.rpc_runtime.runtime().spawn(rpc_call);