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

Drop stderr/stdout reader may cause some unexpected behavior #71

Open
DCjanus opened this issue Oct 30, 2021 · 0 comments
Open

Drop stderr/stdout reader may cause some unexpected behavior #71

DCjanus opened this issue Oct 30, 2021 · 0 comments

Comments

@DCjanus
Copy link
Contributor

DCjanus commented Oct 30, 2021

From this function, we took and drop stderr reader, which in my test, not a good idea.

In my simple test, parent process drop reader from child stdout, and child would got a broken pipe error if it's trying to put something to stdout, In Rust, this would cause panic because of this line, but I don't know what would happen in CPP program.

parent code:

fn main() {
    let file = "target/release/child";
    let mut result = std::process::Command::new(file)
        .stdout(Stdio::piped())
        .spawn()
        .unwrap();
    let stdout = result.stdout.take().unwrap();
    let mut reader = BufReader::new(stdout);
    let mut line = String::new();
    reader.read_line(&mut line).unwrap();
    println!("read {} bytes", line.len());
    drop(reader);
    loop {
        println!("waiting");
        sleep(Duration::from_secs(1));
    }
}

child code

fn main() {
    loop {
        println!("{}", "FOOFOOFOOFOOFOO".repeat(128));
        std::fs::write(
            "child.timestamp",
            UNIX_EPOCH.elapsed().unwrap().as_secs().to_string(),
        )
        .unwrap();
        sleep(Duration::from_secs(1));
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant