diff --git a/src/gateway/server-close.ts b/src/gateway/server-close.ts index da9f5a39e..9977c0a3c 100644 --- a/src/gateway/server-close.ts +++ b/src/gateway/server-close.ts @@ -3,6 +3,7 @@ import type { WebSocketServer } from "ws"; import type { CanvasHostHandler, CanvasHostServer } from "../canvas-host/server.js"; import { type ChannelId, listChannelPlugins } from "../channels/plugins/index.js"; import { stopGmailWatcher } from "../hooks/gmail-watcher.js"; +import { killAllChildren, killAllChildrenSync } from "../infra/child-registry.js"; import type { HeartbeatRunner } from "../infra/heartbeat-runner.js"; import type { PluginServicesHandle } from "../plugins/services.js"; @@ -124,5 +125,11 @@ export function createGatewayCloseHandler(params: { httpServer.close((err) => (err ? reject(err) : resolve())), ); } + + // Phase 3: Kill any orphaned children not stopped by their own managers + await killAllChildren("SIGTERM", { excludeManaged: true, timeoutMs: 2000 }); + + // Phase 4: Force cleanup of any remaining children + killAllChildrenSync(); }; }