NanHan Qing 2377a49217
fix(gateway): close pooled MCP sessions on shutdown (#5961)
* fix(gateway): close pooled MCP sessions on shutdown

The Gateway lifespan closes the browser session manager on the way out but
never closed MCPSessionPool, so every pooled MCP session was abandoned when
the worker exited: the owner task's transport __aexit__ never ran and a stdio
MCP server or SSE/HTTP connection had no orderly teardown.

MCPSessionPool.close_all() already existed for exactly this and had no
production caller -- only the config-retirement path used close_all_sync().
The async form is the right one here: close_all_sync()'s own docstring directs
callers running inside a live event loop to await close_all() instead of
signalling and returning.

Wired into lifespan shutdown with the same bounded, best-effort shape as the
neighbouring browser-session hook.

* fix(gateway): close MCP sessions after run drain

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-09-28 09:14:27 +08:00
..