process: Bugfix: ensure status_async closes child's stdio handles after spawning

This commit is contained in:
Ivan Petkov
2019-06-24 16:56:50 -07:00
parent 34e71fa71a
commit 56d3914675
2 changed files with 34 additions and 5 deletions
+20 -1
View File
@@ -8,11 +8,12 @@ extern crate env_logger;
use std::io;
use std::process::{Stdio, ExitStatus, Command};
use std::time::Duration;
use futures::future::{BoxFuture, Future};
use futures::stream::{self, Stream};
use tokio_io::io::{read_until, write_all, read_to_end};
use tokio_core::reactor::Core;
use tokio_core::reactor::{Core, Timeout};
use tokio_process::{CommandExt, Child};
mod support;
@@ -117,3 +118,21 @@ fn wait_with_output_captures() {
assert_eq!(output.stdout, written);
assert_eq!(output.stderr.len(), 0);
}
#[test]
fn status_closes_any_pipes() {
let mut core = Core::new().unwrap();
// Cat will open a pipe between the parent and child.
// If `status_async` doesn't ensure the handles are closed,
// we would end up blocking forever (and time out).
let child = cat().status_async(&core.handle());
let timeout = Timeout::new(Duration::from_secs(1), &core.handle())
.expect("timeout registration failed")
.map(|()| panic!("time out exceeded! did we get stuck waiting on the child?"));
match core.run(child.select(timeout)) {
Ok((status, _)) => assert!(status.success()),
Err(_) => panic!("failed to run futures"),
}
}