fix(core): stop MCP servers in parallel on shutdown (#58351)

This commit is contained in:
Aiden Cline
2026-10-23 00:50:40 -05:00
committed by GitHub
Unverified
parent 09399e3eec
commit 7b14ad4be0
+4 -1
View File
@@ -181,6 +181,9 @@ export const layer = (options?: Options) =>
const credentials = yield* Credential.Service
const root = yield* Effect.scope
const fork = yield* FiberSet.makeRuntime<never, void, never>()
// Server scopes close in parallel on shutdown, so one slow server's stop grace does not delay
// the rest past a service restart's kill deadline and leave them orphaned.
const servers = yield* Scope.fork(root, "parallel")
const entries = new Map<ServerName, ServerEntry>()
const attached = new Map<ServerName, AttachedEntry[]>()
@@ -451,7 +454,7 @@ export const layer = (options?: Options) =>
// disabled/failed status for the duration of the connection attempt.
entry.status = { status: "pending" }
yield* bus.publish(McpEvent.StatusChanged, { server: name })
const scope = yield* Scope.fork(root)
const scope = yield* Scope.fork(servers)
entry.scope = scope
const authProvider = yield* connectProvider(entry)
const { McpClient } = yield* Effect.promise(() => import("./client.js"))