exec: timeout on grandchildren

We were enforcing the 10 s wall-clock limit only on the child process.
If that child (bash) spawns grandchildren and we kill it on timeout, those
grandchildren still have the original stdout/err pipe open, so the background
tasks that are draining the pipes block forever
This commit is contained in:
Misha Davidov
2025-08-04 15:35:15 -07:00
parent 8782704b0d
commit 3f7d3834c6

View File

@@ -361,14 +361,13 @@ pub(crate) async fn consume_truncated_output(
handle: &mut JoinHandle<std::io::Result<Vec<u8>>>,
timeout: Duration,
) -> std::io::Result<Vec<u8>> {
tokio::select! {
join_res = &mut *handle => {
match join_res {
Ok(io_res) => io_res,
Err(join_err) => Err(std::io::Error::other(join_err)),
}
match tokio::time::timeout(timeout, &mut *handle).await {
Ok(join_res) => match join_res {
Ok(io_res) => io_res,
Err(join_err) => Err(std::io::Error::other(join_err)),
},
_ = tokio::time::sleep(timeout) => {
Err(_elapsed) => {
// Timeout: abort the task to avoid hanging on open pipes.
handle.abort();
Ok(Vec::new())
}