Wait on the plugin child to prevent zombies (#901)

This commit is contained in:
JT 2022-01-31 10:20:11 -05:00 committed by GitHub
parent b1aa8f4edf
commit 96fedb47ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -92,28 +92,26 @@ impl Command for PluginDeclaration {
let reader = stdout_reader; let reader = stdout_reader;
let mut buf_read = BufReader::with_capacity(OUTPUT_BUFFER_SIZE, reader); let mut buf_read = BufReader::with_capacity(OUTPUT_BUFFER_SIZE, reader);
let response = self let response = self.encoding.decode_response(&mut buf_read).map_err(|err| {
.encoding let decl = engine_state.get_decl(call.decl_id);
.decode_response(&mut buf_read) ShellError::SpannedLabeledError(
.map_err(|err| { format!("Unable to decode call for {}", decl.name()),
let decl = engine_state.get_decl(call.decl_id); err.to_string(),
ShellError::SpannedLabeledError( call.head,
format!("Unable to decode call for {}", decl.name()), )
err.to_string(), });
call.head,
)
})?;
match response { match response {
PluginResponse::Value(value) => { Ok(PluginResponse::Value(value)) => {
Ok(PipelineData::Value(value.as_ref().clone(), None)) Ok(PipelineData::Value(value.as_ref().clone(), None))
} }
PluginResponse::Error(err) => Err(err.into()), Ok(PluginResponse::Error(err)) => Err(err.into()),
PluginResponse::Signature(..) => Err(ShellError::SpannedLabeledError( Ok(PluginResponse::Signature(..)) => Err(ShellError::SpannedLabeledError(
"Plugin missing value".into(), "Plugin missing value".into(),
"Received a signature from plugin instead of value".into(), "Received a signature from plugin instead of value".into(),
call.head, call.head,
)), )),
Err(err) => Err(err),
} }
} else { } else {
Err(ShellError::SpannedLabeledError( Err(ShellError::SpannedLabeledError(
@ -121,11 +119,12 @@ impl Command for PluginDeclaration {
"no stdout reader".into(), "no stdout reader".into(),
call.head, call.head,
)) ))
}?; };
// There is no need to wait for the child process to finish // We need to call .wait() on the child, or we'll risk summoning the zombie horde
// The response has been collected from the plugin call let _ = child.wait();
Ok(pipeline_data)
pipeline_data
} }
fn is_plugin(&self) -> Option<(&PathBuf, &str, &Option<PathBuf>)> { fn is_plugin(&self) -> Option<(&PathBuf, &str, &Option<PathBuf>)> {