@@ -187,19 +187,26 @@ impl NymVpnService {
187
187
* self . shared_vpn_state . lock ( ) . unwrap ( ) = state;
188
188
}
189
189
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
+ }
194
196
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 ( ) {
196
200
self . set_shared_state ( VpnState :: Disconnecting ) ;
201
+ } else {
202
+ return VpnServiceDisconnectResult :: NotRunning ;
197
203
}
198
204
199
205
if let Some ( ref mut vpn_ctrl_sender) = self . vpn_ctrl_sender {
200
- let _ = vpn_ctrl_sender
206
+ vpn_ctrl_sender
201
207
. send ( nym_vpn_lib:: NymVpnCtrlMessage :: Stop )
202
- . await ;
208
+ . await
209
+ . ok ( ) ;
203
210
VpnServiceDisconnectResult :: Success
204
211
} else {
205
212
VpnServiceDisconnectResult :: NotRunning
@@ -220,9 +227,7 @@ impl NymVpnService {
220
227
& mut self ,
221
228
credential : Vec < u8 > ,
222
229
) -> 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 ( ) {
226
231
return VpnServiceImportUserCredentialResult :: Fail (
227
232
"Can't import credential while VPN is running" . to_string ( ) ,
228
233
) ;
0 commit comments