Skip to content

Commit 599d440

Browse files
committed
Fix is_running check
1 parent 8abb7f0 commit 599d440

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

nym-vpnd/src/service/vpn_service.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,26 @@ impl NymVpnService {
187187
*self.shared_vpn_state.lock().unwrap() = state;
188188
}
189189

190-
async fn handle_disconnect(&mut self) -> VpnServiceDisconnectResult {
191-
// To handle the mutable borrow we set the state separate from the sending the stop
192-
// message, including the logical check for the ctrl sender twice.
193-
let is_running = self.vpn_ctrl_sender.is_some();
190+
fn is_running(&self) -> bool {
191+
self.vpn_ctrl_sender
192+
.as_ref()
193+
.map(|s| !s.is_closed())
194+
.unwrap_or(false)
195+
}
194196

195-
if is_running {
197+
async fn handle_disconnect(&mut self) -> VpnServiceDisconnectResult {
198+
// To handle the mutable borrow we set the state separate from the sending the stop message
199+
if self.is_running() {
196200
self.set_shared_state(VpnState::Disconnecting);
201+
} else {
202+
return VpnServiceDisconnectResult::NotRunning;
197203
}
198204

199205
if let Some(ref mut vpn_ctrl_sender) = self.vpn_ctrl_sender {
200-
let _ = vpn_ctrl_sender
206+
vpn_ctrl_sender
201207
.send(nym_vpn_lib::NymVpnCtrlMessage::Stop)
202-
.await;
208+
.await
209+
.ok();
203210
VpnServiceDisconnectResult::Success
204211
} else {
205212
VpnServiceDisconnectResult::NotRunning
@@ -220,9 +227,7 @@ impl NymVpnService {
220227
&mut self,
221228
credential: Vec<u8>,
222229
) -> VpnServiceImportUserCredentialResult {
223-
// BUG: this is not correct after a connect/disconnect cycle
224-
let is_running = self.vpn_ctrl_sender.is_some();
225-
if is_running {
230+
if self.is_running() {
226231
return VpnServiceImportUserCredentialResult::Fail(
227232
"Can't import credential while VPN is running".to_string(),
228233
);

0 commit comments

Comments
 (0)