Parcourir la source

Give up the log lock before killing a raft instance.

The apply command thread blocks on the log lock (through the apply
command callback). The kill function will not return before the apply
command thread completes. So holding the log lock while calling
kill() can cause deadlock.
Jing Yang il y a 5 ans
Parent
commit
32fb95c79d
1 fichiers modifiés avec 6 ajouts et 6 suppressions
  1. 6 6
      tests/config/mod.rs

+ 6 - 6
tests/config/mod.rs

@@ -270,16 +270,16 @@ impl Config {
         self.disconnect(index);
 
         unlock(self.network.as_ref()).remove_server(Self::server_name(index));
-        let raft = {
-            let mut state = self.state.lock();
-            state.rafts[index].take()
-        };
+        let raft = self.state.lock().rafts[index].take();
 
-        let mut log = self.log.lock();
-        let data = log.saved[index].read_state();
+        let data = self.log.lock().saved[index].read_state();
+        // Make sure to give up the log lock before calling external code, which
+        // might directly or indirectly block on the log lock, e.g. through
+        // the apply command function.
         if let Some(raft) = raft {
             raft.kill();
         }
+        let mut log = self.log.lock();
         log.saved[index] = Arc::new(persister::Persister::new());
         log.saved[index].save_state(data);
     }