Skip to content

Commit f6c9d30

Browse files
Copilotphiresky
andcommitted
Fix broken pipe issue in custom adapters by running stdin copy concurrently
Co-authored-by: phiresky <[email protected]>
1 parent cc5d950 commit f6c9d30

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/adapters/custom.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
expand::expand_str_ez,
88
matching::{FastFileMatcher, FileMatcher},
99
};
10-
use crate::{join_handle_to_stream, to_io_err};
10+
use crate::to_io_err;
1111
use anyhow::Result;
1212
use async_stream::stream;
1313
use bytes::Bytes;
@@ -188,13 +188,18 @@ pub fn pipe_output(
188188
let mut stdi = cmd.stdin.take().expect("is piped");
189189
let stdo = cmd.stdout.take().expect("is piped");
190190

191-
let join = tokio::spawn(async move {
191+
// Spawn a task to copy input to stdin and close it when done
192+
// This runs concurrently with reading stdout to avoid deadlock
193+
tokio::spawn(async move {
192194
let mut z = inp;
193-
tokio::io::copy(&mut z, &mut stdi).await?;
194-
std::io::Result::Ok(())
195+
let _ = tokio::io::copy(&mut z, &mut stdi).await;
196+
// stdin is automatically dropped and closed here
195197
});
198+
199+
// Return stdout chained with process wait
200+
// The stdin copy task runs independently in the background
196201
Ok(Box::pin(stdo.chain(
197-
proc_wait(cmd, move || format!("subprocess: {cmd_log}")).chain(join_handle_to_stream(join)),
202+
proc_wait(cmd, move || format!("subprocess: {cmd_log}")),
198203
)))
199204
}
200205

0 commit comments

Comments
 (0)