Procházet zdrojové kódy

Fix shutdown procedure.

The network must drop all references to raft, and then raft can be killed.
Jing Yang před 5 roky
rodič
revize
144224d107
2 změnil soubory, kde provedl 9 přidání a 5 odebrání
  1. 4 4
      src/lib.rs
  2. 5 1
      tests/config/mod.rs

+ 4 - 4
src/lib.rs

@@ -359,9 +359,9 @@ impl Raft {
                 cancel_handle.map(|c| c.send(()));
             }
 
-            // `this` is dropped right here. We cannot drop(this) anymore.
-            let stop_wait_group = this.stop_wait_group;
+            let stop_wait_group = this.stop_wait_group.clone();
             // Making sure the rest of `this` is dropped before the wait group.
+            drop(this);
             drop(stop_wait_group);
         })
     }
@@ -597,9 +597,9 @@ impl Raft {
                 }
             }
 
-            // `this` is dropped right here. We cannot drop(this) anymore.
-            let stop_wait_group = this.stop_wait_group;
+            let stop_wait_group = this.stop_wait_group.clone();
             // Making sure the rest of `this` is dropped before the wait group.
+            drop(this);
             drop(stop_wait_group);
         })
     }

+ 5 - 1
tests/config/mod.rs

@@ -135,8 +135,12 @@ impl Config {
     pub fn end(&self) {}
 
     pub fn cleanup(&self) {
+        let mut network = unlock(&self.network);
+        for i in 0..self.server_count {
+            network.remove_server(Self::server_name(i));
+        }
         for raft in &mut self.state.lock().rafts {
-            if let Some(_raft) = raft.take() {
+            if let Some(raft) = raft.take() {
                 raft.kill();
             }
         }