fix(desktop): don't let spec.onShutdown abort stop() teardown
Inside stop(), Ref.modify atomically flips state to "no active run, no restart fiber" before spec.onShutdown is invoked, but the physical teardown (Fiber.interrupt + closeRun) runs *after* the mutex releases. If onShutdown raised, the whole mutex effect failed and both cleanup steps were skipped — leaving the child process and restart fiber running while state claimed nothing was active. The next start() would then spawn a second backend on top. Wrap the onShutdown call in Effect.ignore so its failure can't abort the surrounding teardown. Matches the pattern closeRun already uses for the same reason.
This commit is contained in:
1 parent
9df70127ca
commit
604de5d345
1 file changed
+9
-1
@@ -656,7 +656,15 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
|
||||
restartFiber: Option.none<Fiber.Fiber<void, never>>(),
|
||||
},
|
||||
]);
|
||||
yield* spec.onShutdown?.() ?? Effect.void;
|
||||
// Ignore failures from spec.onShutdown so a downstream throw
|
||||
// can't abort the rest of stop(). Ref.modify above already
|
||||
// flipped state to "no active run / no restart fiber", and the
|
||||
// physical cleanup (Fiber.interrupt + closeRun) runs after the
|
||||
// mutex releases. If onShutdown were allowed to propagate, both
|
||||
// would be skipped and the child process + restart fiber would
|
||||
// be orphaned while state claimed nothing was running — the
|
||||
// next start() would then spawn a second backend on top.
|
||||
yield* (spec.onShutdown?.() ?? Effect.void).pipe(Effect.ignore);
|
||||
return result;
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user