Skip to content

Commit

Permalink
Write to stdin in a separate thread
Browse files Browse the repository at this point in the history
Avoid deadlock when the child process writes to stdout and fills the
buffer.

See rust-lang/rust@ce2d95c
  • Loading branch information
rafaelfranca committed Mar 19, 2024
1 parent 2717f49 commit d69e0d0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ fn main() {
.spawn()
.expect("Failed to execute process");

let stdin = child.stdin.as_mut().expect("Failed to open stdin");
stdin.write_all(dockerfile).unwrap();
let mut stdin = child.stdin.take().expect("Failed to open stdin");
std::thread::spawn(move || {
stdin.write_all(dockerfile).unwrap();
});

let status = child.wait().expect("failed to wait on child");

Expand Down

0 comments on commit d69e0d0

Please sign in to comment.