Skip to content

Kill child process tree when cancelling git clone#309248

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-clone-cancel-kill-process-298177
Open

Kill child process tree when cancelling git clone#309248
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/git-clone-cancel-kill-process-298177

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

Summary

  • When cancelling a git clone operation, child.kill() only terminates the immediate git process but leaves child processes (e.g. git-remote-https) running in the background
  • On Windows this is especially problematic since TerminateProcess does not affect descendant processes
  • Added a killProcessTree() helper that uses taskkill /T /F on Windows and process.kill(-pid, 'SIGTERM') on Unix to kill the entire process tree when cancellation is requested

Test plan

  • Start a git clone of a large repository via the Git: Clone command
  • Cancel the operation via the notification toast
  • Verify the git process and its child processes are no longer running (check Task Manager on Windows or ps on Unix)
  • Verify the cloned directory can be deleted immediately (no file locks held)

Fixes #298177

When a user cancels a git clone operation, the UI shows it as cancelled
but the underlying git process and its child processes continue running
in the background, consuming resources and holding file locks.

The existing code calls child.kill() which only terminates the immediate
process. On Windows, this does not affect child processes spawned by git
(e.g. git-remote-https). On Unix, SIGTERM to the parent may not always
propagate to all descendants.

Add a killProcessTree() helper that:
- On Windows: uses taskkill /T /F to kill the entire process tree
- On Unix: sends SIGTERM to the process group via kill(-pid)
- Falls back to child.kill() if tree kill fails

Fixes microsoft#298177
@vs-code-engineering
Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/src/git.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cancel git clone does not kill the git process

2 participants