Repository navigation
fix(Deferred): guard waiter cleanup against post-completion runs - #7193
Merged
tim-smart merged 2 commits intoAug 12, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: 04ea598 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
Completion resumes every waiter and sets `resumes` to undefined. A waiter's interrupt cleanup that runs after completion dereferenced the cleared array: TypeError: undefined is not an object (evaluating 'self.resumes.indexOf'). Observed in production at 4.0.0-beta.101 (long-poll HTTP handler, request abort interrupting the awaiting fiber); the code is unchanged at head.
Waiters resume by running the completion effect, so suspending inside it leaves the await cleanup on the waiter's stack after `doneUnsafe` has cleared `resumes`. Interrupting the waiter from that tick runs the cleanup post-completion, which died with TypeError: Cannot read properties of undefined (reading 'indexOf') before the guard.
kitlangton
force-pushed
the
deferred-cleanup-after-completion
branch
from
August 12, 2026 01:51
d1daa86 to
04ea598
Compare
kitlangton
marked this pull request as ready for review
August 12, 2026 01:51
tim-smart
approved these changes
Aug 12, 2026
Merged
This was referenced Aug 20, 2026
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #7194
What
Interrupting a
Deferred.awaitwaiter after theDeferredhas completed dies withTypeError: undefined is not an object (evaluating 'self.resumes.indexOf')— the defect replaces the interrupt cause, so the fiber exitsDieinstead of interrupted. Observed in production at4.0.0-beta.101(long-poll handler, request abort racing a concurrent completion → HTTP 500s); code unchanged at head.Before / After
Before:
_await's cleanup unconditionally dereferencedself.resumes, butdoneUnsafesets it toundefinedafter resuming waiters — so any cleanup running post-completion crashed.After: the cleanup early-returns when
resumesis already cleared (and splices only on a found index, so a stale cleanup can never remove another waiter's registration viasplice(-1, 1)).sequenceDiagram participant W as Waiter fiber participant D as Deferred participant I as Interruptor W->>D: await — push resume, get cleanup I->>D: complete (doneUnsafe) D->>W: resume(effect) — waiter suspends in completion effect D->>D: resumes = undefined I->>W: interruptUnsafe() W->>D: cleanup: resumes.indexOf ❌ TypeError → Die Note over W,D: after fix: cleanup sees resumes cleared, returns — waiter exits interrupted ✓Testing
New test:
await - interrupting a waiter after completion does not die. Deterministic: the completion effect suspends (yieldNow), so the resumed waiter's async-finalizer frame is still on its stack when it is interrupted, which runs the cleanup post-completion. Fails on the unguarded code with exactly the production defect; passes with the guard (verified both ways).pnpm vitest run --project effect— 8104 passed; the one failure (unstable/cli/Prompt.test.ts, date formatting) is pre-existing on an unmodified treepnpm --dir packages/effect check,oxlint,dprint check— cleaneffectpatch