winjob

package
v0.70.0-rc.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Rendered for windows/amd64

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

This section is empty.

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 New

func New() (*Job, error)

New creates a job object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE set.

func (*Job) Assign

func (j *Job) Assign(pid int) error

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) Close

func (j *Job) Close() error

Close terminates every process still in the job and releases the handle. Safe to call more than once, concurrently, and on a nil *Job.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL