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.
This commit is contained in:
Josh Gratton committed 2026-05-18 12:56:39 -04:00
1 parent ba31706c20
commit 8a55a5565c
1 file changed
+11 -2
+11 -2
View File
@@ -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;