Skip to content

Conversation

LeeEirc
Copy link

@LeeEirc LeeEirc commented Apr 15, 2025

Prevents memory leaks from stream writer

@nadeemcite
Copy link

Can you check if this can solve #514

Copy link
Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

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
Copy link
Author

LeeEirc commented Apr 15, 2025

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 LeeEirc requested a review from Kludex April 15, 2025 15:20
@lcamhoa
Copy link

lcamhoa commented Apr 25, 2025

@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

@LeeEirc LeeEirc closed this May 4, 2025
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