FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

perf: clean up SSE session writer by LeeEirc · Pull Request #518 · modelcontextprotocol/python-sdk · GitHub

Repository navigation

perf: clean up SSE session writer - #518

Closed
LeeEirc wants to merge 2 commits into
modelcontextprotocol:mainfrom
LeeEirc:perf_sse
Closed

LeeEirc wants to merge 2 commits into
modelcontextprotocol:mainfrom
LeeEirc:perf_sse

Conversation

LeeEirc commented Apr 15, 2025

Copy link
Copy Markdown

Prevents memory leaks from stream writer

Copy link
Copy Markdown

Can you check if this can solve #514

Kludex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't think this is the way to go. BackgroundTasks only works on 2xx responses, but also, this kind of logic is more suited as a middleware. Where do we create the session_id? We should probably drop it in the same place.

LeeEirc commented Apr 15, 2025

Copy link
Copy Markdown
Author

The SseServerTransport class contains a memory leak due to improper cleanup of the _read_stream_writers collection. This issue needs to be addressed to prevent resource exhaustion during extended runtime.

 async def connect_sse(self, scope: Scope, receive: Receive, send: Send):
    ......
    session_id = uuid4()
    session_uri = f"{quote(self._endpoint)}?session_id={session_id.hex}"
    self._read_stream_writers[session_id] = read_stream_writer
    logger.debug(f"Created new session with ID: {session_id}")
    .....

LeeEirc requested a review from Kludex April 15, 2025 15:20
Comment thread src/mcp/server/sse.py Outdated

lcamhoa commented Apr 25, 2025

Copy link
Copy Markdown

@Kludex I make a PR for this one also #582 to clean up the memory writer when sse disconnect . SSE Disconnect event handler is new feature I request on sysid/sse-starlette#127

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

5 participants


Back | FazBrowse Home | New Git URL