diff --git a/.changeset/llhi-sqkr-oest.md b/.changeset/llhi-sqkr-oest.md new file mode 100644 index 0000000..bb4b33e --- /dev/null +++ b/.changeset/llhi-sqkr-oest.md @@ -0,0 +1,5 @@ +--- +"ff-effect": patch +--- + +Fix memory leak in Inngest handler: scope step FiberSets per invocation instead of leaking finalizers into the long-lived app scope diff --git a/packages/effect/src/for/inngest/index.ts b/packages/effect/src/for/inngest/index.ts index 5d6a28b..e7bee04 100644 --- a/packages/effect/src/for/inngest/index.ts +++ b/packages/effect/src/for/inngest/index.ts @@ -9,7 +9,6 @@ import type { InngestFunction, } from 'inngest'; import { serve } from 'inngest/bun'; -import { extract } from '../../extract'; import { cronToString } from './cron'; import { wrapStep } from './step'; @@ -114,7 +113,6 @@ export function createInngest< ) => Effect.gen(function* () { const c = yield* Tag; - const ext_handler = yield* extract(handler); const resolvedTrigger = resolveTrigger(trigger); const runPromise = yield* FiberSet.makeRuntimePromise(); @@ -125,13 +123,15 @@ export function createInngest< async (ctx: any) => { const effectStep = wrapStep(ctx.step); return runPromise( - ext_handler({ - ...ctx, - step: effectStep, - } as unknown as EffectHandlerCtx< - TClient, - ExtractTriggerName - >), + Effect.scoped( + handler({ + ...ctx, + step: effectStep, + } as unknown as EffectHandlerCtx< + TClient, + ExtractTriggerName + >), + ) as unknown as Effect.Effect, ); }, ) as unknown as InngestFunction.Any;