Skip to content

fix: introspector lifecycle robustness (child-process kill, eviction TOCTOU)#142

Merged
bug-ops merged 2 commits into
masterfrom
fix/132-130-introspector-cleanup
Jul 9, 2026
Merged

fix: introspector lifecycle robustness (child-process kill, eviction TOCTOU)#142
bug-ops merged 2 commits into
masterfrom
fix/132-130-introspector-cleanup

Conversation

@bug-ops

@bug-ops bug-ops commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

Both issues were found in the same CI-007 live-testing/architecture-review cycle and share the area: bridge label; bundled into one PR since they're small, independent, related fixes to introspector lifecycle robustness.

Test plan

  • cargo +nightly fmt --check
  • cargo +stable clippy --all-targets --all-features --workspace -- -D warnings
  • cargo nextest run --all-features --workspace --no-fail-fast (720/720 passed, 0 leaked)
  • cargo test --doc --all-features --workspace
  • RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace
  • New regression tests: test_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)
  • CHANGELOG.md updated under [Unreleased]

@github-actions github-actions Bot added area: bridge MCP bridge and integration crate: mcp-introspector Changes to mcp-introspector crate (MCP server analysis) type: documentation Documentation changes (*.md, docs/, comments) type: dependencies Dependency updates (Cargo.toml, Cargo.lock) type: tests Test changes (tests/, *_test.rs) workspace Workspace-wide changes affecting multiple crates breaking change Contains breaking API changes (requires major version bump) release Release preparation (changelog, version bumps) labels Jul 9, 2026
bug-ops added 2 commits July 9, 2026 18:19
…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
bug-ops enabled auto-merge (squash) July 9, 2026 16:19
@bug-ops
bug-ops force-pushed the fix/132-130-introspector-cleanup branch from db0ebd6 to 072c925 Compare July 9, 2026 16:19
@bug-ops
bug-ops merged commit d2d86f4 into master Jul 9, 2026
17 checks passed
@bug-ops
bug-ops deleted the fix/132-130-introspector-cleanup branch July 9, 2026 16:23
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: bridge MCP bridge and integration breaking change Contains breaking API changes (requires major version bump) crate: mcp-introspector Changes to mcp-introspector crate (MCP server analysis) release Release preparation (changelog, version bumps) type: dependencies Dependency updates (Cargo.toml, Cargo.lock) type: documentation Documentation changes (*.md, docs/, comments) type: tests Test changes (tests/, *_test.rs) workspace Workspace-wide changes affecting multiple crates

Projects

None yet

1 participant