fix: introspector lifecycle robustness (child-process kill, eviction TOCTOU)#142
Merged
Conversation
…rver timeout discover_server relied on rmcp's TokioChildProcess Drop impl to clean up the spawned child, which defers the actual kill to a tokio::spawn task. Under a short-lived tokio runtime that task can be starved before it ever runs, leaking the child process; nextest reported both timeout-firing tests as LEAK on every run. discover_server now spawns the child directly, keeps the Child handle for its own lifetime, and kills it synchronously once the discovery round-trip finishes, regardless of outcome.
GeneratorService::evict_introspector removed the per-server-id map entry keyed by server_id alone. If a caller's discover_server call finished and evicted while another in-flight caller for the same id was still running, a later caller could insert a fresh handle that the finishing caller would then evict out from under it, defeating the per-id serialization the lock exists to provide. evict_introspector now takes the caller's own Arc<Mutex<Introspector>> handle and only removes the map entry via a ptr_eq compare-and-remove, so a caller can only ever evict the entry it created.
bug-ops
enabled auto-merge (squash)
July 9, 2026 16:19
bug-ops
force-pushed
the
fix/132-130-introspector-cleanup
branch
from
July 9, 2026 16:19
db0ebd6 to
072c925
Compare
This was referenced Jul 9, 2026
bug-ops
added a commit
that referenced
this pull request
Jul 9, 2026
…ture (#152) TokioChildProcess was replaced by a manually spawned stdio pair in #142, leaving only ConfigureCommandExt as a user of this feature. Rewrite spawn_introspection_child to mutate the Command directly so the feature (and its transitive deps: process-wrap, nix, and several Windows-only crates) can be dropped entirely. Closes #146
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
discover_servernow spawns its MCP server child process directly and kills it synchronously once the discovery round-trip finishes, instead of relying on rmcp'sTokioChildProcessDrop-spawned kill task, which a short-lived tokio runtime could starve before it ran.nextestno longer reports the two timeout-firing tests asLEAK.GeneratorService::evict_introspectoris now identity-checked viaArc::ptr_eqcompare-and-remove instead of removing byserver_idalone, so a finishing caller can no longer evict a different in-flight caller's live entry for the same server id.Both issues were found in the same CI-007 live-testing/architecture-review cycle and share the
area: bridgelabel; bundled into one PR since they're small, independent, related fixes to introspector lifecycle robustness.Test plan
cargo +nightly fmt --checkcargo +stable clippy --all-targets --all-features --workspace -- -D warningscargo nextest run --all-features --workspace --no-fail-fast(720/720 passed, 0 leaked)cargo test --doc --all-features --workspaceRUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspacetest_discover_server_connect_timeout_kills_child_process,test_discover_server_discover_timeout_kills_child_process,test_discover_server_success_kills_child_process(poll for actual OS process exit),test_stale_eviction_does_not_remove_unrelated_entry(A/B/C interleaving from mcp-server: introspector per-server-id lock eviction is not identity-checked, can evict a live entry (TOCTOU) #130)[Unreleased]