Skip to content

Commit

Permalink
Kill intproxy on a bogus binary. (#2510)
Browse files Browse the repository at this point in the history
* Kill intproxy on a bogus binary.

* expect

* changelog

* cr suggestions / kill before if / use start_kill

* fix macos

* clippy
  • Loading branch information
meowjesty authored Jun 12, 2024
1 parent e717c92 commit 9443e00
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/2386.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Kill the intproxy child process when mirrord-cli execvp fails.
11 changes: 11 additions & 0 deletions mirrord/cli/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ where
}

impl MirrordExecution {
/// Starts the internal proxy (`intproxy`), and mirrord-layer, even if a bogus binary
/// was passed by the user.
#[tracing::instrument(level = "trace", skip_all)]
pub(crate) async fn start<P>(
config: &LayerConfig,
Expand Down Expand Up @@ -362,4 +364,13 @@ impl MirrordExecution {
.map_err(CliError::InternalProxyWaitError)?;
Ok(())
}

/// Kills the child process, stopping the internal proxy, and completing the agent.
///
/// Used when mirrord execution fails inside `execvp`.
pub async fn stop(self) {
let Self { mut child, .. } = self;

let _ = child.start_kill();
}
}
7 changes: 6 additions & 1 deletion mirrord/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ where
#[cfg(target_os = "macos")]
let (_did_sip_patch, binary) = match execution_info.patched_path {
None => (false, args.binary.clone()),
Some(sip_result) => (true, sip_result),
Some(ref sip_result) => (true, sip_result.to_owned()),
};

#[cfg(not(target_os = "macos"))]
Expand Down Expand Up @@ -120,6 +120,10 @@ where
let err = execvp(binary.clone(), binary_args.clone());
error!("Couldn't execute {:?}", err);
analytics.set_error(AnalyticsError::BinaryExecuteFailed);

// Kills the intproxy, freeing the agent.
execution_info.stop().await;

#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
if let exec::Error::Errno(errno) = err {
if Into::<i32>::into(errno) == 86 {
Expand All @@ -129,6 +133,7 @@ where
}
}
}

Err(CliError::BinaryExecuteFailed(binary, binary_args))
}

Expand Down

0 comments on commit 9443e00

Please sign in to comment.