mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 07:09:11 +02:00
fix(proxy): shield stateful proxy disconnect during session teardown (#4363)
This commit is contained in:
parent
5fa4f32cca
commit
ddcdf64813
1 changed files with 7 additions and 1 deletions
|
|
@ -1232,7 +1232,13 @@ class StatefulProxyClient(ProxyClient[ClientTransportT]):
|
|||
async def _on_session_exit():
|
||||
self._caches.pop(session)
|
||||
logger.debug(f"{proxy_client} will be disconnect")
|
||||
await proxy_client._disconnect(force=True)
|
||||
# This callback runs while the server session's exit stack is
|
||||
# unwinding, which usually happens because the owning task is
|
||||
# being cancelled. Shield the disconnect so the forced cleanup
|
||||
# actually runs to completion instead of aborting at the first
|
||||
# cancellation checkpoint (e.g. acquiring the session lock).
|
||||
with anyio.CancelScope(shield=True):
|
||||
await proxy_client._disconnect(force=True)
|
||||
|
||||
session._exit_stack.push_async_callback(_on_session_exit)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue