| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Fixes modelcontextprotocol#1450 - HTTP responses don't get closed properly when SSE streaming fails with exceptions in _handle_sse_response and _handle_resumption_request. The issue: when the async for loop throws an exception, response.aclose() never gets called because it's only in the success path. Added reproduction script and pytest tests to demonstrate the problem. The fix requires adding finally blocks to ensure response.aclose() always gets called.
|
Marking as a draft for now since this is only a reproduction and not a completed fix |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #1450
I found that HTTP responses don't get closed properly when SSE streaming fails with exceptions in the streamable HTTP client.
The Problem:
When the async for loop in _handle_sse_response and _handle_resumption_request throws an exception (malformed JSON, network error, etc.), the response is never closed because response.aclose() is only called in the success path.
Impact:
This can cause connection pool exhaustion in long-running clients, eventually causing new requests to hang or fail.
What I Added:
Both test files show that when SSE parsing fails, the response doesn't get closed, confirming the resource leak.
The Fix:
The methods need finally blocks to ensure response.aclose() is always called:
This ensures resources are properly cleaned up regardless of whether exceptions occur.