Skip to content

[Server] Fix stdio answering a request on an idle connection only after ~50ms - #575

Merged
chr-hertel merged 2 commits into
modelcontextprotocol:mainfrom
chr-hertel:fix-stdio-idle-latency
Oct 13, 2026
Merged

chr-hertel merged 2 commits into
modelcontextprotocol:mainfrom
chr-hertel:fix-stdio-idle-latency

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

The stdio loop slept 50ms whenever no complete line was there, so a sequential client got ~20 calls/s at most.

  • Wait on the input with stream_select() instead, still capped at 50ms so fibers, streams and queued messages get their tick
  • Non-selectable streams like php://memory fall back to the sleep

Fixes chr-hertel#63

🤖 Generated with Claude Code

@chr-hertel chr-hertel added this to the 0.9.0 milestone Oct 10, 2026
@chr-hertel chr-hertel added bug Something isn't working Server Issues & PRs related to the Server component labels Oct 10, 2026
@chr-hertel
chr-hertel requested a balanced review from Copilot October 12, 2026 20:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new process-based unit test must skip environments where proc_open() is disabled.

1 open finding
What changed in this PR

Replaces stdio polling sleeps with selectable input waits to reduce idle-request latency.

Changes:

  • Adds a 50ms-capped stream_select() wait with fallback.
  • Adds latency regression coverage.
  • Documents the fix in the changelog.
File Description
src/​Server/​Transport/​StdioTransport.php Adds interruptible input waiting.
tests/​Unit/​Server/​Transport/​StdioTransportTest.php Tests idle-input wake-up latency.
CHANGELOG.md Records the latency fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/Unit/Server/Transport/StdioTransportTest.php
@chr-hertel
chr-hertel force-pushed the fix-stdio-idle-latency branch from 3860c21 to 20d6dd5 Compare October 12, 2026 20:56
soyuka
soyuka previously approved these changes Oct 13, 2026
@chr-hertel
chr-hertel force-pushed the fix-stdio-idle-latency branch from 20d6dd5 to 9df0acb Compare October 13, 2026 21:27
@chr-hertel
chr-hertel merged commit 6a8fd25 into modelcontextprotocol:main Oct 13, 2026
54 of 56 checks passed
@chr-hertel
chr-hertel deleted the fix-stdio-idle-latency branch October 13, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Server] stdio answers a lone request only after ~50 ms

3 participants