Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: drop pipe after child exits in wait_with_output #4315

Merged
merged 2 commits into from Jan 10, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions tokio/src/process/mod.rs
Expand Up @@ -1130,19 +1130,25 @@ impl Child {
pub async fn wait_with_output(mut self) -> io::Result<Output> {
use crate::future::try_join3;

async fn read_to_end<A: AsyncRead + Unpin>(io: Option<A>) -> io::Result<Vec<u8>> {
async fn read_to_end<A: AsyncRead + Unpin>(io: &mut Option<A>) -> io::Result<Vec<u8>> {
let mut vec = Vec::new();
if let Some(mut io) = io {
crate::io::util::read_to_end(&mut io, &mut vec).await?;
if let Some(io) = io.as_mut() {
crate::io::util::read_to_end(io, &mut vec).await?;
}
Ok(vec)
}

let stdout_fut = read_to_end(self.stdout.take());
let stderr_fut = read_to_end(self.stderr.take());
let mut stdout_pipe = self.stdout.take();
let mut stderr_pipe = self.stderr.take();

let stdout_fut = read_to_end(&mut stdout_pipe);
let stderr_fut = read_to_end(&mut stderr_pipe);

let (status, stdout, stderr) = try_join3(self.wait(), stdout_fut, stderr_fut).await?;

drop(stdout_pipe);
Darksonn marked this conversation as resolved.
Show resolved Hide resolved
drop(stderr_pipe);
Darksonn marked this conversation as resolved.
Show resolved Hide resolved

Ok(Output {
status,
stdout,
Expand Down