devbox icon indicating copy to clipboard operation
devbox copied to clipboard

Support passing `SIGINT` to scripts that are running via `devbox run`

Open kadaan opened this issue 1 year ago • 5 comments

What problem are you trying to solve?

Scripts run via devbox run cannot be cancelled with SIGINT.

What solution would you like?

Handle the SIGINT signal and pass it to the script being execute by devbox run.

Alternatives you've considered

Not running scripts via devbox. That is not desirable as the scripts defined in devbox.json provide a great way to catalog functionality.

kadaan avatar Feb 15 '24 03:02 kadaan

It does seem to be working some of the time. I've yet to determine why is it not working all the time. Some scripts correctly respond to SIGINT when run but they don't when run via devbox run.

kadaan avatar Feb 15 '24 03:02 kadaan

This seems similar to the issues that this PR fixed in dagger: https://github.com/dagger/dagger/pull/5712

Their change is essentially doing the following to nix/run.go:

cmd := exec.CommandContext(ctx, shPath, "-c", cmdWithArgs)
	cmd.Env = envPairs
	cmd.Dir = projectDir
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.Cancel = func() error {
		return syscall.Kill(cmd.Process.Pid, syscall.SIGTERM)
	}

With my limited testing, this seems to fix the issue.

kadaan avatar Feb 15 '24 17:02 kadaan

Thanks for the submitting a PR with your fix. I'd still like to understand a bit more why this is happening. Could you provide a few more details?

  • What's the exact script that's not responding to SIGINT?
  • What shell are you using (for running devbox and the script)?
  • Are you sending SIGINT by pressing ctrl-c in the shell? Or are you signaling the devbox process directly?
  • Is this happening on macOS or Linux?

When I try to repro using this config:

{
  "shell": {
    "scripts": {
      "zzz": "/bin/sleep 5"
    }
  }
}

and run devbox run zzz followed by ctrl-c, the sleep process exits. This is what I'd expect because the shell should be signaling the entire process group.

gcurtis avatar Feb 21 '24 05:02 gcurtis

@gcurtis Here is some more info:

  1. I'm trying to identify the actual cause. It is intermittent...
  2. zsh
  3. SIGINT is sent by pressing CTRL-C in the shell that is executing via devbox run...
  4. MacOS

kadaan avatar Feb 22 '24 19:02 kadaan

I'm seeing this too. I can reliably reproduce on devbox 0.13.5 with the simple ruby script:

sleep

Here is a screen recording:

https://github.com/user-attachments/assets/a3d6eee2-0ea6-480e-9cf1-4a91abd6e426

seven1m avatar Oct 23 '24 20:10 seven1m