fix: send priming event in GET handler to prevent hang #1883
+114
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
GET requests to
/mcpendpoint hang indefinitely when usingstreamable_http_app().Related issue in FastMCP: jlowin/fastmcp#532
Root Cause
The
_handle_get_requestmethod'sstandalone_sse_writerfunction doesn't send a priming event before entering the message loop, unlike the POST handler which calls_maybe_send_priming_event()at line 592.This causes the SSE writer to block waiting for messages that may never arrive, making the GET request appear to hang.
Solution
Send an event immediately after establishing the SSE connection in
standalone_sse_writer():_maybe_send_priming_event()(for SSE resumability support){"event": "open", "data": ""}event to confirm connection is establishedAdditional fixes:
anyio.ClosedResourceErrorhandling for clean shutdown whenclose_standalone_sse_stream()is calledclose_standalone_sse_stream()can properly close itTesting
test_get_request_receives_priming_event_with_event_storeto verify the fixChecklist