fix(core): keep plugin swaps going when a cleanup fails (#63548)

Co-authored-by: Filip Hejmowski <fhejmowski@simplito.com>
This commit is contained in:
Filip
2026-11-12 16:15:41 +01:00
committed by GitHub
Unverified
parent 96d950178c
commit ec263d62b6
2 changed files with 10 additions and 3 deletions
+8 -2
View File
@@ -143,8 +143,14 @@ const layer = Layer.effect(
([id, slot]) =>
Effect.gen(function* () {
active.delete(id)
if (slot.activation && !slot.activation.failure)
yield* Scope.close(slot.activation.scope, Exit.void)
if (!slot.activation || slot.activation.failure) return
// Later plugins, including the config agents and commands, are already closed. A failing
// finalizer must not abort the swap, or they stay unregistered until the next reload.
yield* Scope.close(slot.activation.scope, Exit.void).pipe(
Effect.catchCause((cause) =>
Effect.logError("failed to clean up plugin", { "plugin.id": id, cause }),
),
)
}),
{ discard: true },
)
+2 -1
View File
@@ -672,7 +672,8 @@ export function fromPromise(plugin: Plugin) {
yield* Effect.acquireRelease(
Effect.promise(() => Promise.resolve(plugin.setup(context2))),
(cleanup) => (cleanup ? Effect.promise(() => Promise.resolve(cleanup())) : Effect.void),
// JavaScript plugins may return anything, such as a v1-style hooks object; only a function is a cleanup.
(cleanup) => (typeof cleanup === "function" ? Effect.promise(() => Promise.resolve(cleanup())) : Effect.void),
)
}),
})