Skip to content

Commit 0a1bc19

Browse files
authored
Fix detect_family deadlock (#1626)
* Fix detect_family deadlock Fixed #1623 Due to child blocking on stderr writing and detect_family blocking on child stdout reading * Fix compilation * Remove unused import of std::io::Read * Cargo fmt
1 parent 3ee6682 commit 0a1bc19

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/tool.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ use crate::{
44
tempfile::NamedTempfile,
55
Error, ErrorKind, OutputKind,
66
};
7-
use std::io::Read;
87
use std::{
98
borrow::Cow,
109
collections::HashMap,
1110
env,
1211
ffi::{OsStr, OsString},
1312
io::Write,
1413
path::{Path, PathBuf},
15-
process::{Command, Stdio},
14+
process::{Command, Output, Stdio},
1615
sync::RwLock,
1716
};
1817

@@ -224,16 +223,13 @@ impl Tool {
224223
let mut captured_cargo_output = compiler_detect_output.clone();
225224
captured_cargo_output.output = OutputKind::Capture;
226225
captured_cargo_output.warnings = true;
227-
let mut child = spawn(&mut cmd, &captured_cargo_output)?;
226+
let Output {
227+
status,
228+
stdout,
229+
stderr,
230+
} = spawn(&mut cmd, &captured_cargo_output)?.wait_with_output()?;
228231

229-
let mut out = vec![];
230-
let mut err = vec![];
231-
child.stdout.take().unwrap().read_to_end(&mut out)?;
232-
child.stderr.take().unwrap().read_to_end(&mut err)?;
233-
234-
let status = child.wait()?;
235-
236-
let stdout = if [&out, &err]
232+
let stdout = if [&stdout, &stderr]
237233
.iter()
238234
.any(|o| String::from_utf8_lossy(o).contains("-Wslash-u-filename"))
239235
{
@@ -251,7 +247,7 @@ impl Tool {
251247
));
252248
}
253249

254-
out
250+
stdout
255251
};
256252

257253
let stdout = String::from_utf8_lossy(&stdout);

0 commit comments

Comments
 (0)