Skip to content

Conversation

@ArtemYurov
Copy link
Contributor

Problem:

  • MCP server disconnects after ~60 seconds of inactivity
  • fread() blocks and returns false when no data available
  • This triggers "Failed to read from STDIN" error and breaks the listening loop

Solution (Variant 1):

  • Use stream_select() with 1-second timeout to check data availability before reading
  • Keep feof() check for maximum compatibility with different systems
  • Enable graceful shutdown by checking $this->closing flag every second
  • Prevents blocking while maintaining proper EOF detection

Testing:
✅ Tested for 150+ seconds without disconnections
✅ Compatible with macOS and other UNIX systems
✅ Graceful shutdown works correctly

Changes:

  • Added stream_select() before fread() to wait for available data
  • Short 1-second timeout allows periodic check of $this->closing flag
  • Maintains feof() for EOF detection compatibility
  • Fixed $deferred->resolve() to pass null argument (line 145)

…m_select + feof)

Problem:
- MCP server disconnects after ~60 seconds of inactivity
- fread() blocks and returns false when no data available
- This triggers "Failed to read from STDIN" error and breaks the listening loop

Solution (Variant 1):
- Use stream_select() with 1-second timeout to check data availability before reading
- Keep feof() check for maximum compatibility with different systems
- Enable graceful shutdown by checking $this->closing flag every second
- Prevents blocking while maintaining proper EOF detection

Testing:
✅ Tested for 150+ seconds without disconnections
✅ Compatible with macOS and other UNIX systems
✅ Graceful shutdown works correctly

Changes:
- Added stream_select() before fread() to wait for available data
- Short 1-second timeout allows periodic check of $this->closing flag
- Maintains feof() for EOF detection compatibility
- Fixed $deferred->resolve() to pass null argument (line 145)
@butschster butschster merged commit 39dc557 into context-hub:main Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants