Skip to content

Leaking STDIO client: Unclosed <MemoryObjectReceiveStream> #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
EItanya opened this issue Jan 24, 2025 · 1 comment · May be fixed by #515
Open

Leaking STDIO client: Unclosed <MemoryObjectReceiveStream> #169

EItanya opened this issue Jan 24, 2025 · 1 comment · May be fixed by #515
Labels
bug Something isn't working

Comments

@EItanya
Copy link

EItanya commented Jan 24, 2025

Describe the bug
A clear and concise description of what the bug is.

While running the MCP stdio client I noticed that my application was logging a warning from the anyio library, specifically related to unclosed streams.

When I dug in further I noticed that the stdio client does not close any of the streams after completing, see the following link.

This is as opposed to the sse_client which does close the streams.

Here is a slightly scrubbed more detailed error:

/home/user/src/microsoft/autogen/python/.venv/lib/python3.12/site-packages/anyio/streams/memory.py:183: ResourceWarning: Unclosed <MemoryObjectReceiveStream at 7f5394255fa0>
  warnings.warn(
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/home/user/src/microsoft/autogen/python/.venv/lib/python3.12/site-packages/anyio/streams/memory.py:313: ResourceWarning: Unclosed <MemoryObjectSendStream at 7f5394256270>
  warnings.warn(
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/home/user/src/microsoft/autogen/python/.venv/lib/python3.12/site-packages/anyio/streams/memory.py:183: ResourceWarning: Unclosed <MemoryObjectReceiveStream at 7f5394256de0>
  warnings.warn(
ResourceWarning: Enable tracemalloc to get the object allocation traceback

The context here is that I am trying to add support for MCP to microsoft/autogen but this is most likely a blocker.

To Reproduce

As mentioned, I am running this code from another project, but this should be easily reproducible with a small example, I will try to do that and update if I find anything.

Expected behavior

No warnings should be logged as these streams should be properly closed

Screenshots
If applicable, add screenshots to help explain your problem.

@dsp-ant dsp-ant added the bug Something isn't working label Jan 28, 2025
@DmitriyLeybel
Copy link

Also encountering a similar issue.
/workspaces/pyllments/.venv/lib/python3.13/site-packages/anyio/streams/memory.py:183: ResourceWarning: Unclosed <MemoryObjectReceiveStream at 7f0876332fd0>

bhosmer-ant added a commit that referenced this issue Apr 15, 2025
Wraps the request handling in a try/finally block to ensure that response
streams are properly closed and removed from the tracking dictionary, even
if an exception occurs during request processing.

This change also prevents response_stream and response_stream_reader
instances from piling up on _exit_stack over the course of the session.

Github-Issue:#169
@bhosmer-ant bhosmer-ant linked a pull request Apr 15, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants