Browse Source

fix deadlock on sso network leave

Grant Limberg 3 years ago
parent
commit
dac32f863e
2 changed files with 13 additions and 10 deletions
  1. 6 0
      zeroidc/src/ext.rs
  2. 7 10
      zeroidc/src/lib.rs

+ 6 - 0
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);
     }

+ 7 - 10
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 {