From ac2d39fc34ad624f202679581a97a24ef4c340d6 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Thu, 30 Apr 2026 18:02:39 +0800 Subject: [PATCH] runtime-rs: Add sandbox exit notifier in VirtSandbox Add an internal exit_notify_tx channel to VirtSandbox and initialise it in both the regular and restore constructors. The later WaitSandbox rework needs a way to block until sandbox stop has been observed without polling runtime state. This commit only wires in the notifier so the follow-on behaviour change can subscribe to a dedicated stop signal. No WaitSandbox behaviour changes are made here yet. Signed-off-by: Alex Lyn --- .../crates/runtimes/virt_container/src/sandbox.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 cd61d52439..2007461fcd 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs @@ -77,7 +77,7 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::SystemTime; use strum::Display; -use tokio::sync::{mpsc::Sender, Mutex, RwLock}; +use tokio::sync::{mpsc::Sender, watch, Mutex, RwLock}; use tracing::instrument; pub(crate) const VIRTCONTAINER: &str = "virt_container"; @@ -118,6 +118,7 @@ pub struct VirtSandbox { agent: Arc, hypervisor: Arc, monitor: Arc, + exit_notify_tx: watch::Sender, sandbox_config: Option, shm_size: u64, factory: Option, @@ -133,6 +134,7 @@ impl std::fmt::Debug for VirtSandbox { .field("agent", &"") .field("hypervisor", &self.hypervisor) .field("monitor", &"") + .field("exit_notify_tx", &">") .field("sandbox_config", &self.sandbox_config) .field("factory", &self.factory) .finish() @@ -151,6 +153,7 @@ impl VirtSandbox { ) -> Result { let config = resource_manager.config().await; let keep_abnormal = config.runtime.keep_abnormal; + let (exit_notify_tx, _) = watch::channel(false); Ok(Self { sid: sid.to_string(), msg_sender: Arc::new(Mutex::new(msg_sender)), @@ -159,6 +162,7 @@ impl VirtSandbox { hypervisor, resource_manager, monitor: Arc::new(HealthCheck::new(true, keep_abnormal)), + exit_notify_tx, shm_size: sandbox_config.shm_size, sandbox_config: Some(sandbox_config), factory: Some(factory), @@ -1254,6 +1258,7 @@ impl Persist for VirtSandbox { hypervisor, resource_manager, monitor: Arc::new(HealthCheck::new(true, keep_abnormal)), + exit_notify_tx: watch::channel(false).0, sandbox_config: None, shm_size: DEFAULT_SHM_SIZE, factory: None,