Initial Checks
Description
I'm seeing occasional errors from our MCP server, which I think are a race condition during shutdown.
I think this is a similar but distinct issue to the race condition in #1190 and #1384 as this is during send_log_message
I haven't been able to get a consistent reproduce yet, will update when I can.
Stack Trace
+ExceptionGroupTraceback (mostrecentcalllast):
|File"/app/.venv/lib/python3.13/site-packages/mcp/server/streamable_http_manager.py", line180, inrun_stateless_server|awaitself.app.run(
| ...<4lines>...
| )
|File"/app/.venv/lib/python3.13/site-packages/fastmcp/server/low_level.py", line202, inrun|asyncwithAsyncExitStack() asstack:
|~~~~~~~~~~~~~~^^|File"/usr/local/lib/python3.13/contextlib.py", line768, in__aexit__|raiseexc|File"/usr/local/lib/python3.13/contextlib.py", line751, in__aexit__|cb_suppress=awaitcb(*exc_details)
|^^^^^^^^^^^^^^^^^^^^^^|File"/app/.venv/lib/python3.13/site-packages/mcp/shared/session.py", line238, in__aexit__|returnawaitself._task_group.__aexit__(exc_type, exc_val, exc_tb)
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|File"/app/.venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line783, in__aexit__|raiseBaseExceptionGroup(
|"unhandled errors in a TaskGroup", self._exceptions| ) fromNone|ExceptionGroup: unhandlederrorsinaTaskGroup (1sub-exception)
+-+----------------1----------------|ExceptionGroupTraceback (mostrecentcalllast):
|File"/app/.venv/lib/python3.13/site-packages/fastmcp/server/low_level.py", line214, inrun|asyncwithanyio.create_task_group() astg:
|~~~~~~~~~~~~~~~~~~~~~~~^^|File"/app/.venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line783, in__aexit__|raiseBaseExceptionGroup(
|"unhandled errors in a TaskGroup", self._exceptions| ) fromNone|ExceptionGroup: unhandlederrorsinaTaskGroup (1sub-exception)
+-+----------------1----------------|Traceback (mostrecentcalllast):
|File"/app/.venv/lib/python3.13/site-packages/mcp/server/lowlevel/server.py", line694, in_handle_message|awaitsession.send_log_message(
| ...<3lines>...
| )
|File"/app/.venv/lib/python3.13/site-packages/mcp/server/session.py", line213, insend_log_message|awaitself.send_notification(
| ...<10lines>...
| )
|File"/app/.venv/lib/python3.13/site-packages/mcp/shared/session.py", line335, insend_notification|awaitself._write_stream.send(session_message)
|File"/app/.venv/lib/python3.13/site-packages/anyio/streams/memory.py", line249, insend|self.send_nowait(item)
|~~~~~~~~~~~~~~~~^^^^^^|File"/app/.venv/lib/python3.13/site-packages/anyio/streams/memory.py", line218, insend_nowait|raiseClosedResourceError|anyio.ClosedResourceError+------------------------------------
Python & MCP Python SDK
MCP SDK Version: 1.25.0
via fastmcp Version: 2.14.4
Python Version: 3.13.5
Initial Checks
Description
I'm seeing occasional errors from our MCP server, which I think are a race condition during shutdown.
I think this is a similar but distinct issue to the race condition in #1190 and #1384 as this is during
send_log_messageI haven't been able to get a consistent reproduce yet, will update when I can.
Stack Trace
Python & MCP Python SDK
MCP SDK Version: 1.25.0
via fastmcp Version: 2.14.4
Python Version: 3.13.5