Documentation
¶
Overview ¶
Package winjob provides Windows Job Object based process-tree cleanup.
Unix has process groups: kill(-pgid, sig) reaches every descendant a spawned command has forked. Windows has no equivalent for an arbitrary process tree — Process.Kill() only ever reaches the one PID mcpproxy itself started (e.g. cmd.exe), never the grandchildren cmd.exe/npx/bash go on to spawn (node.exe, python.exe, the real MCP server). Those grandchildren were left running forever every time a stdio server was restarted, reconnected, or disconnected — see internal/upstream/core/process_windows.go and internal/upstream/launcher/launcher_windows.go, both previously TODO stubs that only killed the immediate child.
A Job Object created with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE restores the process-group-kill guarantee on Windows: once the immediate child is assigned to the job, every process IT spawns afterwards automatically joins the same job (job membership is inherited on process creation), so terminating the job reaches the whole tree in one call — matching what killProcessGroup already does on Unix via kill(-pgid, ...).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSuspended ¶ added in v0.71.0
IsSuspended reports whether cmd was marked to start suspended.
func MarkSuspended ¶ added in v0.71.0
MarkSuspended makes cmd start with its main thread suspended. It keeps any SysProcAttr fields the caller already set. Call it before cmd.Start.
Types ¶
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
Job wraps a Windows Job Object configured to kill every member process (including any it spawns after joining) as soon as Close is called.
Close may be reached from more than one goroutine at once — the launcher's Stop path and its reaper both close the job — so the handle is guarded by a mutex and Close is idempotent.
func (*Job) Assign ¶
Assign adds the process with the given PID to the job. Must be called as soon as possible after the process starts — everything it spawns AFTER joining inherits job membership, but anything it spawns BEFORE joining (a race in principle) would escape. In practice the caller starts the child and assigns it within the same goroutine with no intervening work, so the window is negligible — the child (a shell/npx wrapper) has not yet had a chance to exec its own grandchild.
func (*Job) AssignAndResume ¶ added in v0.71.0
AssignAndResume adds a suspended process to the job and only then lets it run, so everything it ever spawns is a member of the job. On an error the process is still suspended; the caller kills it.