diff --git a/src/runtime-rs/crates/resource/src/cgroups/mod.rs b/src/runtime-rs/crates/resource/src/cgroups/mod.rs index 367e9fba83..9a176c2fd8 100644 --- a/src/runtime-rs/crates/resource/src/cgroups/mod.rs +++ b/src/runtime-rs/crates/resource/src/cgroups/mod.rs @@ -100,13 +100,16 @@ impl CgroupsResource { for cg_pid in self.cgroup_manager.tasks() { self.cgroup_manager.remove_task(cg_pid); } - self.cgroup_manager.delete()?; + + self.cgroup_manager + .delete() + .context("delete cgroup manager")?; if let Some(overhead) = self.overhead_cgroup_manager.as_ref() { for cg_pid in overhead.tasks() { overhead.remove_task(cg_pid); } - overhead.delete()?; + overhead.delete().context("delete overhead")?; } Ok(()) diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/container_manager/io/shim_io.rs b/src/runtime-rs/crates/runtimes/virt_container/src/container_manager/io/shim_io.rs index 03a4c387b4..7559fe2ee4 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/container_manager/io/shim_io.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/container_manager/io/shim_io.rs @@ -18,7 +18,7 @@ use nix::{ sys::stat::Mode, }; use tokio::{ - fs::File, + fs::OpenOptions, io::{AsyncRead, AsyncWrite}, net::UnixStream as AsyncUnixStream, }; @@ -47,8 +47,20 @@ impl ShimIo { stdout: &Option, stderr: &Option, ) -> Result { + info!( + sl!(), + "new shim io stdin {:?} stdout {:?} stderr {:?}", stdin, stdout, stderr + ); + let stdin_fd: Option> = if let Some(stdin) = stdin { - match File::open(&stdin).await { + info!(sl!(), "open stdin {:?}", &stdin); + match OpenOptions::new() + .read(true) + .write(false) + .custom_flags(libc::O_NONBLOCK) + .open(&stdin) + .await + { Ok(file) => Some(Box::new(file)), Err(err) => { error!(sl!(), "failed to open {} error {:?}", &stdin, err); @@ -60,6 +72,8 @@ impl ShimIo { }; let get_url = |url: &Option| -> Option { + info!(sl!(), "get url for {:?}", url); + match url { None => None, Some(out) => match Url::parse(out.as_str()) { @@ -79,6 +93,7 @@ impl ShimIo { let stdout_url = get_url(stdout); let get_fd = |url: &Option| -> Option> { + info!(sl!(), "get fd for {:?}", &url); if let Some(url) = url { if url.scheme() == "fifo" { let path = url.path(); diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/container_manager/process.rs b/src/runtime-rs/crates/runtimes/virt_container/src/container_manager/process.rs index 927e2d10c5..334488453a 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/container_manager/process.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/container_manager/process.rs @@ -129,13 +129,24 @@ impl Process { mut reader: Box, mut writer: Box, ) -> Result<()> { + info!(self.logger, "run io copy for {}", io_name); let io_name = io_name.to_string(); let logger = self.logger.new(o!("io name" => io_name)); let _ = tokio::spawn(async move { - match tokio::io::copy(&mut reader, &mut writer).await { - Err(e) => warn!(logger, "io: failed to copy stream {}", e), - Ok(length) => warn!(logger, "io: stop to copy stream length {}", length), - }; + loop { + match tokio::io::copy(&mut reader, &mut writer).await { + Err(e) => { + if let Some(error_code) = e.raw_os_error() { + if error_code == libc::EAGAIN { + continue; + } + } + warn!(logger, "io: failed to copy stream {}", e); + } + Ok(length) => warn!(logger, "io: stop to copy stream length {}", length), + }; + break; + } wgw.done(); }); 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 6bcf3d2dfc..5f9625ad75 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs @@ -210,13 +210,16 @@ impl Sandbox for VirtSandbox { async fn stop(&self) -> Result<()> { info!(sl!(), "begin stop sandbox"); - // TODO: stop sandbox + self.hypervisor.stop_vm().await.context("stop vm")?; Ok(()) } async fn shutdown(&self) -> Result<()> { info!(sl!(), "shutdown"); + self.stop().await.context("stop")?; + + info!(sl!(), "delete cgroup"); self.resource_manager .delete_cgroups() .await