From 8a55a5565c74a41ac8f52578cd9ccd97734e5f41 Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Mon, 18 May 2026 12:56:39 -0400 Subject: [PATCH] fix(desktop): stop every pool instance on normal shutdown, not just primary Same pattern as the update-install path (ba31706c) but on the normal quit path. The scoped program finalizer was only stopping the primary backend before marking shutdown complete, so any registered WSL instance was left for the layer-scope cascade to clean up. The electronApp.quit() in listenForQuit can race ahead of that cascade, hard-killing the WSL child instead of letting it receive SIGTERM + grace. Iterate pool.list and stop every instance concurrently. --- apps/desktop/src/app/DesktopApp.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/app/DesktopApp.ts b/apps/desktop/src/app/DesktopApp.ts index befa38167e..b05cd4e403 100644 --- a/apps/desktop/src/app/DesktopApp.ts +++ b/apps/desktop/src/app/DesktopApp.ts @@ -235,10 +235,19 @@ const scopedProgram = Effect.scoped( const shutdown = yield* DesktopLifecycle.DesktopShutdown; const pool = yield* DesktopBackendPool.DesktopBackendPool; - const primaryBackend = yield* pool.primary; yield* Effect.addFinalizer(() => - primaryBackend.stop().pipe(Effect.ensuring(shutdown.markComplete)), + Effect.gen(function* () { + // Stop every backend in the pool, not just the primary. The + // electronApp.quit() path can race ahead of the layer-scope + // cascade, so leaving the WSL instance for its parent scope + // finalizer means it gets hard-killed by the OS instead of + // receiving SIGTERM + grace. Stops run concurrently. + const instances = yield* pool.list; + yield* Effect.forEach(instances, (instance) => instance.stop(), { + concurrency: "unbounded", + }); + }).pipe(Effect.ensuring(shutdown.markComplete)), ); yield* startup;