mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 14:04:18 +02:00
Add timeout to client cleanup to prevent hangs
When the MCP SDK's transport tries to terminate a session during cleanup, it can hang if the server is unresponsive (e.g., rate-limited). Adding a 5-second timeout ensures we don't block forever during `__aexit__`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a8bbd745fe
commit
6faef9d96f
1 changed files with 5 additions and 1 deletions
|
|
@ -374,7 +374,11 @@ class Client(Generic[ClientTransportT]):
|
|||
return await self._connect()
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
await self._disconnect()
|
||||
# Use a timeout to prevent hanging during cleanup if the connection is in a bad
|
||||
# state (e.g., rate-limited). The MCP SDK's transport may try to terminate the
|
||||
# session which can hang if the server is unresponsive.
|
||||
with anyio.move_on_after(5):
|
||||
await self._disconnect()
|
||||
|
||||
async def _connect(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue