소스 검색

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 5 년 전
부모
커밋
32fb95c79d
1개의 변경된 파일6개의 추가작업 그리고 6개의 파일을 삭제
  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);
     }