Browse Source

Fail all new and inflight requests at shutdown time.

Jing Yang 3 years ago
parent
commit
222b18d355
1 changed files with 10 additions and 0 deletions
  1. 10 0
      src/verify_authority.rs

+ 10 - 0
src/verify_authority.rs

@@ -357,6 +357,11 @@ impl VerifyAuthorityDaemon {
     }
 
     pub fn kill(&self) {
+        let term = self.state.lock().term;
+        // Fail all inflight verify authority requests. It is important to do
+        // this so that the RPC framework could drop requests served by us and
+        // release all references to the Raft instance.
+        self.reset_state(term);
         self.condvar.notify_all();
     }
 }
@@ -415,6 +420,11 @@ impl<Command: 'static + Send> Raft<Command> {
     pub fn verify_authority_async(
         &self,
     ) -> Option<impl Future<Output = crate::VerifyAuthorityResult>> {
+        // Fail the request if we have been killed.
+        if !self.keep_running.load(Ordering::Acquire) {
+            return None;
+        }
+
         let (term, commit_index) = {
             let rf = self.inner_state.lock();
             if !rf.is_leader() {