mcpproxy-go icon indicating copy to clipboard operation
mcpproxy-go copied to clipboard

Launcher teardown leaves a descendant running when the launcher process exits first

Open Dumbris opened this issue 1 month ago • 0 comments

Summary

A locally launched HTTP/SSE upstream (command + url) whose launcher process backgrounds a long-lived descendant with redirected streams and then exits leaves that descendant running after mcpproxy tears the server down.

Where

  • internal/upstream/launcher/launcher.go, stopLocked: returns at once when Done is closed (the leader exited), so no signal reaches the rest of its process group.
  • internal/upstream/core/connection_launcher.go, watchLauncher: on leader exit after connect it calls Disconnect → stopLauncher → Stop, which is that no-op. The descendant becomes an orphan.

Reproduce

Server config: "command": "/bin/sh", "args": ["-c", "/usr/bin/python3 server.py PORT </dev/null >/dev/null 2>&1 &"], "url": "http://127.0.0.1:PORT/mcp". The instance connects (the backgrounded server answers), watchLauncher logs upstream child exited unexpectedly, disconnecting, and server.py keeps running in the old process group after the server is removed.

Observed on the Spec 116 PR4 branch (#1612) and on main.

Scope note

This is the ordinary teardown path, not retirement. PR #1612 (Spec 116 PR4, review round 2) makes the retirement kill (Handle.Kill) reach a descendant left in the group after the leader exited. It records the group at spawn and does not signal a group whose number was reused. Teardown was left unchanged to keep that PR in scope.

Suggested fix

After Stop, stopLauncher (and the connect-failure cleanups) could call handle.Kill(), which now has the reused-ID guard. Alternatively, decide that a launcher which daemonizes is unsupported and document it. The instance already disconnects when the leader exits.

Dumbris avatar Oct 13 '26 08:10 Dumbris