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

Fix debugged process not being terminated when debugging session closes on Linux #620

Merged

Conversation

vpyatnitskiy
Copy link
Contributor

This is a follow-up for #613. Both PRs need to be merged for this change to work.

Issue:

On Linux, when debugging session is initiated and then closed from VS Code, the game (i.e. the process being debugged) does not terminate.

Steps to reproduce are as you would expect:

  1. Have a launch configuration for GDScript in VS Code properly set up.

  2. Launch a project with F5.

  3. Switch back to VS Code. Press Shift+F5 to close the debugging session.

  4. The session closes but the project continues running.

Cause:

  • Similar to Fix child processes not being killed properly #613, the debugger process is started with shell: true flag, which causes child_process.spawn() to first start a shell process which, in turn, starts the actual debugger. The returned PID is the shell's PID; the debugger runs under a different PID.

  • When a debugging session terminates, the shell PID is killed. However, in Linux, child processes are allowed to persist when their parent is killed, so the debugger process survives.

  • Contrary to Fix child processes not being killed properly #613, the debugger is not launched with detached: true ― which means it is also running under its own process group, and is effectively inaccessible to VS Code.

Solution:

Add detached: true to force both processes to share a process group. Rely on the change from #613 to kill the entire group rather than individual process(es).

Other notes:

Unlike #613, this change is not restricted to Linux, and may potentially cause unintended consequences on Windows and/or Mac OS. This shouldn't be the case assuming headless LSP works properly on these platforms, but more extensive testing is necessary.

In case it does cause problems on other platforms, the suggested fix is to set the flag depending on the platform, e.g. detached: process.platform !== "win32" && process.platform !== "darwin" or similar.

Additionally, Godot 3 integration may need to be tested separately since it uses a separate code path.

vpyatnitskiy and others added 2 commits March 11, 2024 18:42
See discussion near godotengine#613 (comment) .

Currently, the debugger process is spawned with `shell: true` option, which
means a shell process is launched first, and its PID is returned.

When a debugging session terminates, `godot-tools` attempts to kill the process.
However, on Linux, calling `process.kill()` on that kills the shell process,
while allowing the main process to keep running.

To fix, enable `detached: true` flag when launching the debugger to force
both processes to share the same process group; then rely on changes
introduced in godotengine#613
to kill the entire group.
@Calinou Calinou added the bug label Mar 11, 2024
@enekonieto
Copy link

enekonieto commented Mar 23, 2024

This solves the issue using Linux and Godot 3.5.3

@DaelonSuzuka
Copy link
Collaborator

@vpyatnitskiy Thanks for doing the legwork on this.

@DaelonSuzuka DaelonSuzuka merged commit 0fc399b into godotengine:master Apr 17, 2024
4 checks passed
@DaelonSuzuka
Copy link
Collaborator

I quickly tested master after merging and it looks like killing the child works correctly on Windows using both 3.5 and 4.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants