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

Unable to kill running processes #924

Open
jcf opened this issue Jan 6, 2024 · 8 comments
Open

Unable to kill running processes #924

jcf opened this issue Jan 6, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@jcf
Copy link

jcf commented Jan 6, 2024

Describe the bug

Attempting to kill running processes with ctrl-c results in an exception from Python:

Traceback (most recent call last):
  File "/nix/store/vpvlpmh0p39f6q34njjq38wr9y9q1cz9-honcho-1.1.0/bin/.honcho-wrapped", line 9, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nix/store/vpvlpmh0p39f6q34njjq38wr9y9q1cz9-honcho-1.1.0/lib/python3.11/site-packages/honcho/command.py", line 291, in main
    COMMANDS[args.command](args)
  File "/nix/store/vpvlpmh0p39f6q34njjq38wr9y9q1cz9-honcho-1.1.0/lib/python3.11/site-packages/honcho/command.py", line 237, in command_start
    manager.loop()
  File "/nix/store/vpvlpmh0p39f6q34njjq38wr9y9q1cz9-honcho-1.1.0/lib/python3.11/site-packages/honcho/manager.py", line 115, in loop
    self._printer.write(msg)
  File "/nix/store/vpvlpmh0p39f6q34njjq38wr9y9q1cz9-honcho-1.1.0/lib/python3.11/site-packages/honcho/printer.py", line 61, in write
    print(prefix + line, file=self.output, flush=True)
  File "/nix/store/vpvlpmh0p39f6q34njjq38wr9y9q1cz9-honcho-1.1.0/lib/python3.11/site-packages/honcho/manager.py", line 95, in _terminate
    self._system_print("%s received\n" % SIGNALS[signum]['name'])
  File "/nix/store/vpvlpmh0p39f6q34njjq38wr9y9q1cz9-honcho-1.1.0/lib/python3.11/site-packages/honcho/manager.py", line 191, in _system_print
    self._printer.write(Message(type='line',
  File "/nix/store/vpvlpmh0p39f6q34njjq38wr9y9q1cz9-honcho-1.1.0/lib/python3.11/site-packages/honcho/printer.py", line 61, in write
    print(prefix + line, file=self.output, flush=True)
RuntimeError: reentrant call inside <_io.BufferedWriter name='<stdout>'>

A second attempt to ctrl-c tells the user the expected PID file does not exist:

^C22:57:47 system     | SIGINT received
Stopping processes...
cat: /Users/jcf/code/uncle/.devenv/state/devenv.pid: No such file or directory
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
rm: cannot remove '/Users/jcf/code/uncle/.devenv/state/devenv.pid': No such file or directory

At this point you're stuck and have to kill -9 the process.

To reproduce

{
  description = "Reproduction";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    devenv.url = "github:cachix/devenv";
  };

  nixConfig = {
    extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
    extra-substituters = "https://devenv.cachix.org";
  };

  outputs = inputs @ {flake-parts, ...}:
    flake-parts.lib.mkFlake {inherit inputs;} {
      imports = [
        inputs.devenv.flakeModule
      ];

      systems = [
        "x86_64-linux"
        "i686-linux"
        "x86_64-darwin"
        "aarch64-linux"
        "aarch64-darwin"
      ];

      perSystem = {
        config,
        self',
        inputs',
        pkgs,
        system,
        ...
      }: {
        packages.default = pkgs.temporal-cli;

        devenv.shells.default = {
          name = "default";
          packages = [config.packages.default];
          languages.clojure.enable = true;

          processes = {
            temporal.exec = "temporal server start-dev";
          };
        };
      };
    };
}
flake.lock
{
  "nodes": {
    "devenv": {
      "inputs": {
        "flake-compat": "flake-compat",
        "nix": "nix",
        "nixpkgs": "nixpkgs",
        "pre-commit-hooks": "pre-commit-hooks"
      },
      "locked": {
        "lastModified": 1703939110,
        "narHash": "sha256-GgjYWkkHQ8pUBwXX++ah+4d07DqOeCDaaQL6Ab86C50=",
        "owner": "cachix",
        "repo": "devenv",
        "rev": "7354096fc026f79645fdac73e9aeea71a09412c3",
        "type": "github"
      },
      "original": {
        "owner": "cachix",
        "repo": "devenv",
        "type": "github"
      }
    },
    "flake-compat": {
      "flake": false,
      "locked": {
        "lastModified": 1673956053,
        "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
        "owner": "edolstra",
        "repo": "flake-compat",
        "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
        "type": "github"
      },
      "original": {
        "owner": "edolstra",
        "repo": "flake-compat",
        "type": "github"
      }
    },
    "flake-parts": {
      "inputs": {
        "nixpkgs-lib": "nixpkgs-lib"
      },
      "locked": {
        "lastModified": 1704152458,
        "narHash": "sha256-DS+dGw7SKygIWf9w4eNBUZsK+4Ug27NwEWmn2tnbycg=",
        "owner": "hercules-ci",
        "repo": "flake-parts",
        "rev": "88a2cd8166694ba0b6cb374700799cec53aef527",
        "type": "github"
      },
      "original": {
        "id": "flake-parts",
        "type": "indirect"
      }
    },
    "flake-utils": {
      "inputs": {
        "systems": "systems"
      },
      "locked": {
        "lastModified": 1685518550,
        "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "gitignore": {
      "inputs": {
        "nixpkgs": [
          "devenv",
          "pre-commit-hooks",
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1660459072,
        "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
        "owner": "hercules-ci",
        "repo": "gitignore.nix",
        "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
        "type": "github"
      },
      "original": {
        "owner": "hercules-ci",
        "repo": "gitignore.nix",
        "type": "github"
      }
    },
    "lowdown-src": {
      "flake": false,
      "locked": {
        "lastModified": 1633514407,
        "narHash": "sha256-Dw32tiMjdK9t3ETl5fzGrutQTzh2rufgZV4A/BbxuD4=",
        "owner": "kristapsdz",
        "repo": "lowdown",
        "rev": "d2c2b44ff6c27b936ec27358a2653caaef8f73b8",
        "type": "github"
      },
      "original": {
        "owner": "kristapsdz",
        "repo": "lowdown",
        "type": "github"
      }
    },
    "nix": {
      "inputs": {
        "lowdown-src": "lowdown-src",
        "nixpkgs": [
          "devenv",
          "nixpkgs"
        ],
        "nixpkgs-regression": "nixpkgs-regression"
      },
      "locked": {
        "lastModified": 1676545802,
        "narHash": "sha256-EK4rZ+Hd5hsvXnzSzk2ikhStJnD63odF7SzsQ8CuSPU=",
        "owner": "domenkozar",
        "repo": "nix",
        "rev": "7c91803598ffbcfe4a55c44ac6d49b2cf07a527f",
        "type": "github"
      },
      "original": {
        "owner": "domenkozar",
        "ref": "relaxed-flakes",
        "repo": "nix",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1678875422,
        "narHash": "sha256-T3o6NcQPwXjxJMn2shz86Chch4ljXgZn746c2caGxd8=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "126f49a01de5b7e35a43fd43f891ecf6d3a51459",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "nixpkgs-lib": {
      "locked": {
        "dir": "lib",
        "lastModified": 1703961334,
        "narHash": "sha256-M1mV/Cq+pgjk0rt6VxoyyD+O8cOUiai8t9Q6Yyq4noY=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "b0d36bd0a420ecee3bc916c91886caca87c894e9",
        "type": "github"
      },
      "original": {
        "dir": "lib",
        "owner": "NixOS",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "nixpkgs-regression": {
      "locked": {
        "lastModified": 1643052045,
        "narHash": "sha256-uGJ0VXIhWKGXxkeNnq4TvV3CIOkUJ3PAoLZ3HMzNVMw=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
        "type": "github"
      }
    },
    "nixpkgs-stable": {
      "locked": {
        "lastModified": 1685801374,
        "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "c37ca420157f4abc31e26f436c1145f8951ff373",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-23.05",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "nixpkgs_2": {
      "locked": {
        "lastModified": 1704194953,
        "narHash": "sha256-RtDKd8Mynhe5CFnVT8s0/0yqtWFMM9LmCzXv/YKxnq4=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "bd645e8668ec6612439a9ee7e71f7eac4099d4f6",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "pre-commit-hooks": {
      "inputs": {
        "flake-compat": [
          "devenv",
          "flake-compat"
        ],
        "flake-utils": "flake-utils",
        "gitignore": "gitignore",
        "nixpkgs": [
          "devenv",
          "nixpkgs"
        ],
        "nixpkgs-stable": "nixpkgs-stable"
      },
      "locked": {
        "lastModified": 1688056373,
        "narHash": "sha256-2+SDlNRTKsgo3LBRiMUcoEUb6sDViRNQhzJquZ4koOI=",
        "owner": "cachix",
        "repo": "pre-commit-hooks.nix",
        "rev": "5843cf069272d92b60c3ed9e55b7a8989c01d4c7",
        "type": "github"
      },
      "original": {
        "owner": "cachix",
        "repo": "pre-commit-hooks.nix",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "devenv": "devenv",
        "flake-parts": "flake-parts",
        "nixpkgs": "nixpkgs_2"
      }
    },
    "systems": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}

Version

devenv: 0.6.3
@jcf jcf added the bug Something isn't working label Jan 6, 2024
@mcdonc
Copy link
Contributor

mcdonc commented Jan 10, 2024

I haven't delved into how devenv manages processes, but whatever the process manager is should likely be configured to try SIGTERM first, then SIGKILL if the process doesn't die after some number of seconds.

But that's a belt and suspenders thing and it will always likely be best to try to fix whatever is trying-to-die to handle SIGTERM properly.

EDIT: after reading the OP more carefully, I see that it's actually probably the process manager itself that is failing here. Yikes.

@domenkozar
Copy link
Member

Maybe we should switch to https://github.com/F1bonacc1/process-compose by default

@thenonameguy
Copy link
Contributor

thenonameguy commented Jan 13, 2024

Maybe we should switch to https://github.com/F1bonacc1/process-compose by default

Bit biased but heavy +1 to that. I would also recommend an eager-evaluation strategy to the process-compose.yml file along with it.

This avoids the costly 'devenv up' nix eval penalty for the most common use-cases.

@mcdonc
Copy link
Contributor

mcdonc commented Jan 13, 2024

process-compose looks ok (although, at the moment, the "settings.tui" switch is broken; it always starts with the TUI).

FWIW, one thing I'd like to see from whatever proc manager we use as default is a way to use a UNIX domain socket instead of an HTTP port for client/server communication, to make it possible to have more than one project running at a time without needing to remember to change the port.

@mcdonc
Copy link
Contributor

mcdonc commented Jan 13, 2024

(although, at the moment, the "settings.tui" switch is broken; it always starts with the TUI).

I was incorrect, it works. I was just putting the flag in the wrong place.

@mcdonc
Copy link
Contributor

mcdonc commented Jan 14, 2024

My complaint about honcho not stopping its subprocesses while running devenv test is also wrong. This happens with hivemind, overmind, and process-compose too, I think it's some sort of race condition in cli.py.

@domenkozar
Copy link
Member

Fixed in #934

@mcdonc
Copy link
Contributor

mcdonc commented Jan 15, 2024

Fixed in #934

Not quite. The OP was about pressing ctrl-C when devenv up is started without -d. #934 only applies to devenv up -d. This issue remains, and it's a honcho issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants