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(); });