From e1a07ce3c42f771364078a526db00ab2029c0e37 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Thu, 23 Apr 2020 10:57:30 -0700 Subject: [PATCH] vmm: vm: Unpark the threads before shutdown when the current state is paused If the current state is paused that means most of the handles got killed by pthread_kill We need to unpark those threads to make the shutdown worked. Otherwise The shutdown API hangs and the API is not responding afterwards. So before the shutdown call we need to resume the VM make it succeed. Fixes: #817 Signed-off-by: Muminul Islam --- vmm/src/vm.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 3164fb6f2..3d6a03b05 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -576,10 +576,15 @@ impl Vm { } pub fn shutdown(&mut self) -> Result<()> { - let mut state = self.state.try_write().map_err(|_| Error::PoisonedState)?; + let current_state = self.get_state()?; let new_state = VmState::Shutdown; - state.valid_transition(new_state)?; + current_state.valid_transition(new_state)?; + // If the current state is paused that means most of the handles got killed by pthread_kill + // We need to unpark those threads by calling resume + if current_state == VmState::Paused { + self.resume().map_err(Error::Resume)?; + } if self.on_tty { // Don't forget to set the terminal in canonical mode @@ -605,6 +610,8 @@ impl Vm { for thread in self.threads.drain(..) { thread.join().map_err(Error::ThreadCleanup)? } + + let mut state = self.state.try_write().map_err(|_| Error::PoisonedState)?; *state = new_state; Ok(())