From dac32f863e737fff4b6d7e7a73520426dad1a71c Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Mon, 25 Apr 2022 13:56:13 -0700 Subject: [PATCH] fix deadlock on sso network leave --- zeroidc/src/ext.rs | 6 ++++++ zeroidc/src/lib.rs | 17 +++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/zeroidc/src/ext.rs b/zeroidc/src/ext.rs index 05752ab42..4ce25b560 100644 --- a/zeroidc/src/ext.rs +++ b/zeroidc/src/ext.rs @@ -80,6 +80,12 @@ pub extern "C" fn zeroidc_delete(ptr: *mut ZeroIDC) { if ptr.is_null() { return; } + let idc = unsafe { + assert!(!ptr.is_null()); + &mut *ptr + }; + idc.stop(); + unsafe { Box::from_raw(ptr); } diff --git a/zeroidc/src/lib.rs b/zeroidc/src/lib.rs index 76bccc9e3..9d452a250 100644 --- a/zeroidc/src/lib.rs +++ b/zeroidc/src/lib.rs @@ -311,7 +311,9 @@ impl ZeroIDC { } sleep(Duration::from_secs(1)); - running = (*inner_local.lock().unwrap()).running; + { + running = (*inner_local.lock().unwrap()).running; + } } println!("thread done!") @@ -321,21 +323,16 @@ impl ZeroIDC { pub fn stop(&mut self) { let local = self.inner.clone(); - if (*local.lock().unwrap()).running { - if let Some(u) = (*local.lock().unwrap()).oidc_thread.take() { - u.join().expect("join failed"); - } + if self.is_running(){ + (*local.lock().unwrap()).running = false; } } pub fn is_running(&mut self) -> bool { let local = Arc::clone(&self.inner); + let running = (*local.lock().unwrap()).running; - if (*local.lock().unwrap()).running { - true - } else { - false - } + running } pub fn get_exp_time(&mut self) -> u64 {