modelcontextprotocol / modelcontextprotocol/python-sdk
Response leak in SSE handlers
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 24.3k
- Fork
- 4k
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 31
Mô tả
I found a resource leak in the streamable HTTP client. When SSE streaming fails with an exception, the HTTP response isn't closed.
Location:
src/mcp/client/streamable_http.py:
_handle_sse_response(line 336)_handle_resumption_request(line 251)
The Issue:
python
async def _handle_sse_response(self, response: httpx.Response, ...):
try:
event_source = EventSource(response)
async for sse in event_source.aiter_sse():
if is_complete:
await response.aclose() # Only closed here
break
except Exception as e:
await ctx.read_stream_writer.send(e)
# response leaked!
If the SSE iteration raises an exception (malformed JSON, network error, etc.), the response is never closed.
Impact:
Connection pool gets exhausted in long-running clients, eventually causing new requests to hang or fail.
Fix:
try:
...
except Exception as e:
...
finally:
await response.aclose()
Both methods need this fix.
Env:
Python SDK version: 1.1.2 (or main branch)
Python: 3.12
Transport: StreamableHTTP
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Đọc src/mcp/client/streamable_http.py, tập trung vào _handle_sse_response và _handle_resumption_request. Theo dõi cách mỗi phương thức xử lý việc lặp SSE và các ngoại lệ, sau đó xác minh rằng cả hai nhánh đều đóng HTTP response sau các lỗi cũng như sau khi hoàn tất bình thường.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- networking
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 58/100