From e156516bdeb277ca3ea346c26b8689a7b958016b Mon Sep 17 00:00:00 2001 From: Fupan Li Date: Fri, 19 Jul 2024 09:38:28 +0800 Subject: [PATCH] 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 --- .../crates/runtimes/virt_container/src/sandbox.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs index 44883e54b6..d731eb0152 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs @@ -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(()) }