Prevent stdio shutdown aborts and hangs

Merged
WE
17d ago
+246-6

Summary

  • bypass Python interpreter finalization after the MCP stdio server stops
  • handle SIGINT, SIGTERM, and SIGHUP with immediate, deterministic exits
  • add subprocess coverage for signal and stdin-EOF shutdown paths

Problem

The MCP Python SDK's stdio transport performs blocking stdin reads in an AnyIO worker thread. If shutdown begins while that read is still parked, the process can hang or abort during interpreter finalization with _enter_buffered_busy.

Validation

  • uv run --all-extras pytest tests -q -p no:cacheprovider --no-cov — 189 passed
  • shutdown tests pass on Python 3.12 and Python 3.14
  • the new shutdown test reproduces failures against the previous implementation

Fixes https://github.com/weijie-tan3/trino-mcp/issues/60