-
Notifications
You must be signed in to change notification settings - Fork 321
Open
Description
When we send a SIGKILL
to a subprocess, it only terminates that process and not its child processes. Similarly, on Windows, calling TerminateProcess
only terminates that process and not its children.
When we kill a subprocess from SourceKit-LSP, we want to terminate all of its children as well, to make sure that we don’t leave orphan processes behind. Changing this would require:
- On Posix platforms: Ensuring that the process that we launch does not start new process groups for its child processes. In general, we can’t make this guarantee, but for SwiftPM, we should be able to achieve this by setting
startNewProcessGroup: false
for all processes that it launches (or changing the default in TSC). While at it, we should also change SourceKit-LSP to passstartNewProcessGroup: false
for all subprocesses it launches, so that these subprocesses get killed if SourceKit-LSP is killed. This does not cover the processes launched throughFoundation.Process
, in particular the ones launched fromJSONRPCConnection
. - On Windows: We need to create a Job Object when creating the subprocesses so that we can terminate their job (which includes the process and all of its children). This would require breaking behavior changes in swift-corelibs-foundation or a custom Windows process implementation in TSC. Details in https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433.
Alternatively, the Subprocess
type proposed in Foundation seems to not start new process groups and might eventually be a solution for Posix platforms. However, it doesn’t have any mechanism to terminate an entire process tree on Windows. I raised this in the review thread.
Metadata
Metadata
Assignees
Labels
No labels