diff options
| author | Emīls <emils@mullvad.net> | 2019-11-19 14:29:31 +0000 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2019-11-19 14:29:31 +0000 |
| commit | 558ddf57a22c074334759479a43b10c0fcd17b33 (patch) | |
| tree | d803524d6f402bae5ba5059af0a1fbe9a9dd3220 | |
| parent | 429e3dbfadceabc0756ba76fd8c760e8fba5d70d (diff) | |
| parent | 5483637bdb00e7d8c663780984ad5c4e9fddb398 (diff) | |
| download | mullvadvpn-558ddf57a22c074334759479a43b10c0fcd17b33.tar.xz mullvadvpn-558ddf57a22c074334759479a43b10c0fcd17b33.zip | |
Merge branch 'run-routing-on-single-thread'
| -rw-r--r-- | CHANGELOG.md | 3 | ||||
| -rw-r--r-- | mullvad-daemon/src/system_service.rs | 4 | ||||
| -rw-r--r-- | talpid-core/src/routing/mod.rs | 37 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/mod.rs | 7 |
4 files changed, 31 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index fecb1a7d92..0ea5e33d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,9 @@ Line wrap the file at 100 chars. Th minutes to allow for addressing the issue. ### Fixed +#### Linux +- Improved stability on Linux by using the routing netlink socket in it's own thread. + #### Windows - Detect removal of the OpenVPN TAP adapter on reconnection attempts. - Improve robustness in path environment variable logic in Windows installer. Handle the case diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index 607f4b8162..81e96d66a4 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -277,7 +277,9 @@ pub fn install_service() -> Result<(), InstallError> { const FIFTEEN_MINUTES_AS_SECS: u64 = 60 * 15; let failure_actions = ServiceFailureActions { - reset_period: ServiceFailureResetPeriod::After(Duration::from_secs(FIFTEEN_MINUTES_AS_SECS)), + reset_period: ServiceFailureResetPeriod::After(Duration::from_secs( + FIFTEEN_MINUTES_AS_SECS, + )), reboot_msg: None, command: None, actions: Some(recovery_actions), diff --git a/talpid-core/src/routing/mod.rs b/talpid-core/src/routing/mod.rs index 16ee5803ac..6f5b73e014 100644 --- a/talpid-core/src/routing/mod.rs +++ b/talpid-core/src/routing/mod.rs @@ -3,7 +3,6 @@ use futures::{sync::oneshot, Future}; use ipnetwork::IpNetwork; use std::{collections::HashMap, net::IpAddr}; -use tokio_executor::Executor; #[cfg(target_os = "macos")] #[path = "macos.rs"] @@ -22,6 +21,9 @@ pub use imp::Error as PlatformError; /// Errors that can be encountered whilst initializing RouteManager #[derive(err_derive::Error, Debug)] pub enum Error { + /// Routing manager thread panicked before starting routing manager + #[error(display = "Routing manager thread panicked before starting routing manager")] + RoutingManagerThreadPanic, /// Platform sepcific error occured #[error(display = "Failed to create route manager")] FailedToInitializeManager(#[error(source)] imp::Error), @@ -41,21 +43,28 @@ impl RouteManager { /// Constructs a RouteManager and applies the required routes. /// Takes a map of network destinations and network nodes as an argument, and applies said /// routes. - pub fn new( - required_routes: HashMap<IpNetwork, NetNode>, - exec: &mut impl Executor, - ) -> Result<Self, Error> { + pub fn new(required_routes: HashMap<IpNetwork, NetNode>) -> Result<Self, Error> { let (tx, rx) = oneshot::channel(); + let (start_tx, start_rx) = oneshot::channel(); - - let route_manager = imp::RouteManagerImpl::new(required_routes, rx) - .map_err(Error::FailedToInitializeManager)?; - exec.spawn(Box::new( - route_manager.map_err(|e| log::error!("Routing manager failed - {}", e)), - )) - .map_err(|_| Error::FailedToSpawnManager)?; - - Ok(Self { tx: Some(tx) }) + std::thread::spawn( + move || match imp::RouteManagerImpl::new(required_routes, rx) { + Ok(route_manager) => { + let _ = start_tx.send(Ok(())); + if let Err(e) = route_manager.wait() { + log::error!("Route manager failed - {}", e); + } + } + Err(e) => { + let _ = start_tx.send(Err(Error::FailedToInitializeManager(e))); + } + }, + ); + match start_rx.wait() { + Ok(Ok(())) => Ok(Self { tx: Some(tx) }), + Ok(Err(e)) => Err(e), + Err(_) => Err(Error::RoutingManagerThreadPanic), + } } /// Stops RouteManager and removes all of the applied routes. diff --git a/talpid-core/src/tunnel/wireguard/mod.rs b/talpid-core/src/tunnel/wireguard/mod.rs index 3cb99c7d02..c9b6988f7b 100644 --- a/talpid-core/src/tunnel/wireguard/mod.rs +++ b/talpid-core/src/tunnel/wireguard/mod.rs @@ -97,11 +97,8 @@ impl WireguardMonitor { Self::get_tunnel_routes(config), )?); let iface_name = tunnel.get_interface_name(); - let route_handle = routing::RouteManager::new( - Self::get_routes(iface_name, &config), - &mut tokio_executor::DefaultExecutor::current(), - ) - .map_err(Error::SetupRoutingError)?; + let route_handle = routing::RouteManager::new(Self::get_routes(iface_name, &config)) + .map_err(Error::SetupRoutingError)?; let event_callback = Box::new(on_event.clone()); let (close_msg_sender, close_msg_receiver) = mpsc::channel(); let (pinger_tx, pinger_rx) = mpsc::channel(); |
