Skip to content
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

Support passing SIGINT to scripts that are running via devbox run #1815

Open
kadaan opened this issue Feb 15, 2024 · 4 comments · May be fixed by #1825
Open

Support passing SIGINT to scripts that are running via devbox run #1815

kadaan opened this issue Feb 15, 2024 · 4 comments · May be fixed by #1825
Labels
feature New feature or request triage Issue needs triage

Comments

@kadaan
Copy link
Contributor

kadaan commented Feb 15, 2024

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 kadaan added feature New feature or request triage Issue needs triage labels Feb 15, 2024
@kadaan
Copy link
Contributor Author

kadaan commented Feb 15, 2024

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 kadaan closed this as completed Feb 15, 2024
@kadaan kadaan reopened this Feb 15, 2024
@kadaan
Copy link
Contributor Author

kadaan commented Feb 15, 2024

This seems similar to the issues that this PR fixed in dagger: dagger/dagger#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.

@gcurtis
Copy link
Collaborator

gcurtis commented Feb 21, 2024

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.

@kadaan
Copy link
Contributor Author

kadaan commented Feb 22, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request triage Issue needs triage
2 participants