diff options
| author | Emīls <emils@mullvad.net> | 2019-12-05 09:28:53 +0000 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2019-12-05 10:22:59 +0000 |
| commit | 4b4cf8d05f61e192dbfcfa89e1ff584b5e3c0aa6 (patch) | |
| tree | 9462fa564c2981ad350351bf105e4e402d50bddd | |
| parent | 56c617cb8c31b0b8ad6719c3d309c1751fc8125e (diff) | |
| download | mullvadvpn-4b4cf8d05f61e192dbfcfa89e1ff584b5e3c0aa6.tar.xz mullvadvpn-4b4cf8d05f61e192dbfcfa89e1ff584b5e3c0aa6.zip | |
Fix race condition for routing manager
| -rw-r--r-- | talpid-core/src/routing/windows.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/talpid-core/src/routing/windows.rs b/talpid-core/src/routing/windows.rs index 9e70c800fa..171442c7fe 100644 --- a/talpid-core/src/routing/windows.rs +++ b/talpid-core/src/routing/windows.rs @@ -16,6 +16,7 @@ pub type Result<T> = std::result::Result<T, Error>; pub struct RouteManagerImpl { shutdown_rx: oneshot::Receiver<oneshot::Sender<()>>, + is_manager_shut_down: bool, } impl RouteManagerImpl { @@ -41,23 +42,33 @@ impl RouteManagerImpl { } - Ok(Self { shutdown_rx }) + Ok(Self { + shutdown_rx, + is_manager_shut_down: false, + }) + } + + fn shutdown(&mut self) { + if !self.is_manager_shut_down { + winnet::deactivate_routing_manager(); + self.is_manager_shut_down = true; + } } } impl Drop for RouteManagerImpl { fn drop(&mut self) { - winnet::deactivate_routing_manager() + self.shutdown(); } } - impl Future for RouteManagerImpl { type Item = (); type Error = Error; fn poll(&mut self) -> Result<Async<()>> { match self.shutdown_rx.poll() { Ok(Async::Ready(result_tx)) => { + self.shutdown(); if let Err(_e) = result_tx.send(()) { log::error!("Receiver already down"); } |
