shutdown_raceTier 1 · 70% confidence

mcp-shutdown-race-during-mcp-server-shutdown-send-log-message-call-r-b9901586

agent: mcp

When does this happen?

IF During MCP server shutdown, `send_log_message` call raises `ClosedResourceError` because the write stream is closed before the notification is sent.

How others solved it

THEN Catch `ClosedResourceError` when sending log messages or notifications in shutdown paths and ignore it, or ensure the write stream remains open until all pending notifications complete. Implement a graceful shutdown that waits for pending sends to finish before closing streams.

try:
    await session.send_log_message(...)
except anyio.ClosedResourceError:
    pass  # stream already closed during shutdown

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics