Skip to content

Propagate SIGTERM to uv run #6738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion crates/uv/src/commands/tool/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use anyhow::{bail, Context};
use itertools::Itertools;
use owo_colors::OwoColorize;
use tokio::process::Command;
use tokio::select;
use tokio::signal::unix::{signal, SignalKind};
use tracing::{debug, warn};

use distribution_types::{Name, UnresolvedRequirementSpecification};
Expand Down Expand Up @@ -214,7 +216,28 @@ pub(crate) async fn run(
// signal handlers after the command completes.
let _handler = tokio::spawn(async { while tokio::signal::ctrl_c().await.is_ok() {} });

let status = handle.wait().await.context("Child process disappeared")?;
let mut term_signal = signal(SignalKind::terminate())?;
let mut int_signal = signal(SignalKind::interrupt())?;
Comment on lines 216 to +220
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to remove the above ctrl_c() handler if we're going to replicate it here, right?


let status = select! {
status = handle.wait() => status,

// `SIGTERM`
_ = term_signal.recv() => {
handle.kill().await?;
handle.wait().await.context("Child process disappeared")?;
return Ok(ExitStatus::Failure);
}

// `SIGINT`
_ = int_signal.recv() => {
handle.kill().await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be important to preserve the signal kind, so still a SIGINT to the child?

handle.wait().await.context("Child process disappeared")?;
return Ok(ExitStatus::Failure);
}
};

let status = status.context("Child process disappeared")?;

// Exit based on the result of the command
// TODO(zanieb): Do we want to exit with the code of the child process? Probably.
Expand Down
Loading