Skip to content

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

Closed

Description

@kadaan

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.

Activity

  1. kadaan commented on Feb 15, 2024

    @kadaan
    ContributorAuthor

    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.

  2. reopened this on Feb 15, 2024
  3. kadaan commented on Feb 15, 2024

    @kadaan
    ContributorAuthor

    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.

  4. gcurtis commented on Feb 21, 2024

    @gcurtis
    Collaborator

    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.

  5. kadaan commented on Feb 22, 2024

    @kadaan
    ContributorAuthor

    @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
  6. seven1m commented on Oct 23, 2024

    @seven1m

    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:

    Screen.Recording.2024-10-23.at.1.38.24.PM.mov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or requesttriageIssue needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions