-
-
Notifications
You must be signed in to change notification settings - Fork 50
Handle closed connection in StreamTransport
to avoid stuck worker
#290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Handle closed connection in StreamTransport
to avoid stuck worker
#290
Conversation
Hmm one is called runtime, the other one transport, having a runtime interface on a transport feels weird 😐 any ideas? |
Yes it feels weird to me too. But I don't have other ideas for now for testing I could override If someone have guidance, I'll happily modify this! |
StreamTransport
to avoid stuck workerStreamTransport
to avoid stuck worker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR abstracts the StreamTransport
I/O operations behind a RuntimeInterface
to enable testing and improve testability. The main purpose is to handle closed connections in the transport layer to avoid stuck workers.
- Introduces
RuntimeInterface
andRuntime
implementation to wrap PHP's built-in functions - Adds
InMemoryRuntime
test fixture to enable unit testing of transport behavior - Refactors
StreamTransport
to use the runtime interface instead of direct PHP function calls
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/mcp-sdk/src/Server/Transport/Sse/RuntimeInterface.php |
Defines interface for runtime operations (connection status, output buffering, etc.) |
src/mcp-sdk/src/Server/Transport/Sse/Runtime.php |
Production implementation wrapping PHP's built-in functions |
src/mcp-sdk/src/Server/Transport/Sse/StreamTransport.php |
Updated to use runtime interface with default parameter for backward compatibility |
src/mcp-sdk/tests/Fixtures/InMemoryRuntime.php |
Test implementation capturing output for assertions |
src/mcp-sdk/tests/Server/Transport/Sse/StreamTransportTest.php |
Comprehensive unit tests for StreamTransport behavior |
@OskarStark would you be okay if I try the namespaced function override approach just for I couldn’t find other example testing this; even HttpFoundation’s This would avoids the |
I would say give it a try, why not |
56edb8a
to
85b91c4
Compare
Re @OskarStark! I implemented the namespaced override only for |
85b91c4
to
dee0559
Compare
Yes why not 🙌🙂 |
dee0559
to
06f4cfb
Compare
00b17ff
to
d5a43c0
Compare
Hi @OskarStark @chr-hertel (friendly tag because you were tagged in the issue originally)! Quick update:
WDYT about my directions? Happy to have feedback before polishing thing! |
public function __construct( | ||
private JsonRpcHandler $jsonRpcHandler, | ||
private ClockInterface $clock, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about adding a default Clock
like in Symfony Messenger, wdyt?
WIP: I'll update this description with full details as I progress 👍