MCP stdio: optional Linux PR_SET_PDEATHSIG so a server dies with its parent even on SIGKILL / panic=abort

オープン
#414 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
bash, linux, rust
領域
devtools

調査の方向性

Start with the stdio spawn path that sets kill_on_drop(true) and own_process_group, and the StdioOptions builder, to see where a die_with_parent option would hook in. The design question is whether PR_SET_PDEATHSIG should fire on the forking thread's exit under Tokio, so read how tokio::process::Command::spawn forks before writing code. Tests belong in tests/mcp_stdio_test.rs, gated to Linux, covering the SIGKILL case, a control without the option, and the getppid guard. Done means the option works, non-Linux behaviour is decided and documented, and the tests pass.

索引モデルが issue の本文から書いたものです。

説明

enhancement

Asked for by: yoyo-evolve (its #1100). An MCP stdio server should not outlive the host process.

What yoagent does today (0.26.6):

  • Every stdio server is spawned with kill_on_drop(true).
  • StdioOptions::new().own_process_group(true) (0.25.16) puts the server in its own process group. That group is killed on close or drop, and since 0.26.0 also as soon as the command's own exit is seen (an npx → node launcher).
  • A panic that unwinds drops the McpClient, so the server goes too.

The gap: when the parent dies without running destructors, nothing kills the server. That happens on SIGKILL, OOM-kill, panic = "abort", or std::process::exit without dropping the client. The server, and in a process group everything it started, keeps running, reparented to init.

Proposal: an opt-in, Linux-only StdioOptions::die_with_parent(true).

  • In a pre_exec hook it calls prctl(PR_SET_PDEATHSIG, SIGKILL) (via libc, already a cfg(unix) dependency), then checks getppid() against the parent's pid captured before the fork. If the parent is already gone, the child exits. This is the documented race guard.
  • It sits beside own_process_group. The death signal reaches only the direct child (the launcher), so it pairs with own_process_group: the launcher dying is then seen by the existing group cleanup only if yoagent is still alive. Document that a server started through a launcher (npx) may leave grandchildren behind on a SIGKILLed parent, unless the launcher itself forwards the signal.
  • On non-Linux targets, return an error from the builder, or make it a documented no-op (decide which). macOS has no PDEATHSIG; a kqueue NOTE_EXIT watcher in a helper process would be a separate, larger design.
  • Caveat to document: PR_SET_PDEATHSIG fires when the thread that forked exits, not the process. Tokio spawns from a runtime worker thread, so a worker thread exiting (runtime shutdown with the client still alive) would kill the server early. Verify how tokio::process::Command::spawn forks, and whether this needs spawning from a long-lived thread, before choosing the default semantics.

Tests: Linux-only (#[cfg(target_os = "linux")]), in tests/mcp_stdio_test.rs style:

  • Spawn a helper process that starts a bash-scripted server with the option set, record the server's pid, SIGKILL the helper, and assert the server is gone within a bound.
  • A control test without the option: the server survives, then clean it up.
  • The getppid race guard.

Not in scope: changing the default. The option is opt-in, and hosts that already supervise their children (systemd, containers) don't need it.

主要言語
Rust
スター
327
フォーク
46
平均マージ
2時間 36分
マージ済み PR(30日)
107

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

yologdev/yoagent のほかの issue

yologdev/yoagent の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。