thunderstore-io / thunderstore-cli

Thunderstore CLI is a CLI tool for building and publishing Thunderstore packages
24 stars 11 forks source link

`tcli run` orphans game processes upon termination #84

Open krujroom opened 1 year ago

krujroom commented 1 year ago

After staring a game with tcli run, the tcli process will orphan the game process upon termination.

Expected Behavior

After running a game with tcli run, terminating the tcli process (e.g. Ctrl+C, SIGTERM/SIGKILL) should also terminate the game process.

Current Behavior

The game process remains running as an orphan process after the tcli run process is terminated.

Steps to Reproduce

  1. Start a managed game with tcli e.g. tcli.exe run {game identifier}
  2. Verify both the tcli and game process are running:
    $ ps o pid,ppid,pgid,sid,start,time,cmd --forest
     PID    PPID    PGID    SID  STARTED     TIME CMD
    142557  142556  142557  142557 00:17:29 00:00:00 -bash
    142913  142557  142913  142557 00:34:16 00:00:00  \_ tcli run -- -name ModdedTest ..
    142929  142913  142913  142557 00:34:17 00:00:02      \_ /home/valheim/valheim/server/valheim_server.x86_64 -name ModdedTest ...
  3. Terminate the tcli process (e.g. pressing Ctrl+C in a shell or sending SIGTERM/SIGKILL with kill)
  4. Verify the tcli process is terminated, but the game process is running and orphaned:
    $ ps o pid,ppid,pgid,sid,start,time,cmd --forest
      PID    PPID    PGID     SID  STARTED     TIME CMD
    142929       1  142913  142557 00:34:17 00:02:45 /home/valheim/valheim/server/valheim_server.x86_64 -name ModdedTest ...

Workaround

Manually terminate the game process with kill e.g. kill 142929 in example above.

Context (Environment)

Running tcli 0.2.0 with tcli-bepinex-installer 0.1.0 (compiled with an older glibc version) on Debian GNU/Linux 11 (bullseye)

Windows10CE commented 1 year ago

Not much can be done for SIGKILL, but for SIGTERM I can certainly have it try to terminate the game process as well, at least for games not launched through Steam (since I don't have direct control over those).

I vaguely remember ctrl-c working to kill the game process on my system? Could've just been my imagination, but I'll look into it nonetheless.

MythicManiac commented 1 year ago

Perhaps we could also support a pidfile of some kind, making it easier to clean up externally?