sandbox: fix the issue of stop sandbox

Since stop sandbox would be called in multi path,
thus it's better to set and check the sandbox's state.

Fixes: #10042

Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
This commit is contained in:
Fupan Li 2024-07-19 09:38:28 +08:00
parent d7637f93f9
commit e156516bde

View File

@ -471,8 +471,15 @@ impl Sandbox for VirtSandbox {
}
async fn stop(&self) -> Result<()> {
info!(sl!(), "begin stop sandbox");
self.hypervisor.stop_vm().await.context("stop vm")?;
let mut sandbox_inner = self.inner.write().await;
if sandbox_inner.state != SandboxState::Stopped {
info!(sl!(), "begin stop sandbox");
self.hypervisor.stop_vm().await.context("stop vm")?;
sandbox_inner.state = SandboxState::Stopped;
info!(sl!(), "sandbox stopped");
}
Ok(())
}