Skip to content

test(29513): AsyncDisposableStack.disposeAsync awaits each resource - #29564

Open
robobun wants to merge 3 commits into
mainfrom
farm/41279135/asyncdisposablestack-regression-test
Open

robobun wants to merge 3 commits into
mainfrom
farm/41279135/asyncdisposablestack-regression-test

Conversation

@robobun

@robobun robobun commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #29513
Closes #24277

What does this PR do?

Adds regression tests for AsyncDisposableStack. Both underlying bugs were already fixed by a JavaScriptCore upgrade — this PR just adds coverage so a future WebKit bump can't silently regress them.

Root cause

In the JSC shipped with Bun 1.3.0–1.3.11 (through oven-sh/WebKit@00e8255), GetDisposeMethod with an async-dispose hint had two bugs:

(#29513) It wrapped the resource's [Symbol.asyncDispose] in a closure:

return () => {
    try {
        method.@call(value);          // result discarded
    } catch (e) {
        return @promiseReject(@Promise, e);
    }
    return @promiseResolve(@Promise, @undefined);   // always resolved immediately
};

The returned promise from the real disposer was dropped on the floor, so disposeAsync() chained on an already-resolved promise for every resource and finished in ~1ms regardless of how long each disposal actually took. adopt()'s closure had the same problem (() => { onAsyncDispose.call(undefined, value); } — block body, no return).

(#24277) It checked isCallable before checking for undefined/null:

var method = value.@@asyncDispose;
if (!@isCallable(method))
    @throwTypeError("@@asyncDispose must be callable");   // throws for undefined

So passing a resource that only defined [Symbol.dispose] threw instead of falling back to the sync method per GetDisposeMethod.

Both were fixed upstream in WebKit/WebKit@92e52221d299 (the await using implementation rewrote GetDisposeMethod) and landed in Bun via #28371, first released in 1.3.12.

Verification

  • Bun 1.3.11 — reproduces both issues exactly as reported; regression tests fail (use, adopt, and sync-fallback cases)
  • Bun 1.3.12, 1.3.13, bun bd at HEAD — correct sequential LIFO disposal and sync-dispose fallback; regression tests pass (4/4)

The tests use Promise.withResolvers() to control resolution explicitly (no timing-based waits) and assert that each resource's disposal completes before the next begins and before the overall disposeAsync() promise resolves.

@robobun

robobun commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 3:50 PM PT - Jun 16th, 2026

❌ @alii, your commit 8ef2b1f has 1 failures in Build #62951 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 29564

That installs a local version of the PR into your bun-29564 executable, so you can run:

bun-29564 --bun

@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds a new regression test file with four async tests verifying AsyncDisposableStack.disposeAsync() sequencing: LIFO disposal, awaiting Symbol.asyncDispose promises, adopt() and defer() callback ordering, and fallback to Symbol.dispose.

Changes

Cohort / File(s) Summary
Regression tests
test/regression/issue/29513.test.ts
Adds four tests validating AsyncDisposableStack.disposeAsync(): (1) use() disposes LIFO and awaits each Symbol.asyncDispose promise sequentially; (2) adopt() callbacks are awaited in reverse adoption order; (3) use() falls back to Symbol.dispose when Symbol.asyncDispose is absent; (4) defer() callbacks are invoked during disposeAsync() and awaited before resolution.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding regression tests for AsyncDisposableStack.disposeAsync that verify sequential resource disposal.
Description check ✅ Passed The description is comprehensive and well-structured. It clearly explains what the PR does, the root cause of the bugs being tested, verification results across multiple Bun versions, and testing methodology.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

Found 1 issue this PR may fix:

  1. "@@asyncDispose must be callable" when using Disposable in AsyncDisposableStack (bun >=1.3.0) #24277 - The WebKit upgrade (PR Upgrade WebKit to fc9f2fa7272fec64905df6a9c78e15d7912f14ca #28371) that fixed the AsyncDisposableStack awaiting bug also rewrote GetDisposeMethod, which is the same code path that causes sync disposables to be incorrectly rejected with "@@asyncDispose must be callable"

If this is helpful, copy the block below into the PR description to auto-close this issue on merge.

Fixes #24277

🤖 Generated with Claude Code

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only regression coverage for an already-fixed JSC bug.

Extended reasoning...

Overview

This PR adds a single new file, test/regression/issue/29513.test.ts, with three test cases covering AsyncDisposableStack.prototype.disposeAsync() behavior for use(), adopt(), and defer(). No production/source code is touched — the underlying bug was already fixed by a prior JavaScriptCore upgrade (#28371), and this just adds regression coverage.

Security risks

None. This is a pure test addition with no runtime, build, or dependency changes.

Level of scrutiny

Low. Test-only changes in test/regression/issue/ follow an established repo convention. The tests are deterministic (driven by Promise.withResolvers() rather than wall-clock timing), assert correct LIFO sequential disposal per the TC39 spec, and the PR description confirms they fail on 1.3.11 and pass on 1.3.12+/HEAD.

Other factors

No bugs were flagged by the bug-hunting system, no CODEOWNERS apply to this path, and there are no outstanding reviewer comments. The change is small, self-contained, and clearly intentioned.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only regression coverage for AsyncDisposableStack disposal awaiting.

Extended reasoning...

Overview

This PR adds a single new file, test/regression/issue/29513.test.ts, with four regression tests covering AsyncDisposableStack.prototype.disposeAsync(): sequential LIFO awaiting via use(), adopt(), and defer(), plus the Symbol.dispose fallback (issue #24277). No production/runtime code is touched — the underlying fix already landed via a JavaScriptCore upgrade in #28371.

Security risks

None. This is a pure test addition with no I/O, no network, no filesystem access, and no changes to runtime behavior.

Level of scrutiny

Low. Test-only changes in test/regression/issue/ follow the established pattern for issue regression coverage. The tests use Promise.withResolvers() for deterministic resolution control and await Bun.sleep(0) to flush microtasks between assertions, avoiding timing-based flakiness. The PR description confirms the tests fail on 1.3.11 (reproducing the bug) and pass on 1.3.12+ and HEAD.

Other factors

No bugs were flagged by the bug-hunting system, CodeRabbit had no actionable comments, and there are no outstanding reviewer requests. The test logic is straightforward and the assertions correctly encode the spec-required sequential LIFO disposal semantics.

@alii

alii commented Apr 22, 2026

Copy link
Copy Markdown
Member

@robobun resume

@robobun

robobun commented Apr 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

✅ Ready to merge. Test-only PR: adds test/regression/issue/29513.test.ts (161 lines) covering #29513 and #24277. 4/4 pass on every Bun ≥ 1.3.12 and on bun bd under ASAN; correctly fail on 1.3.11.

CI is red on unrelated infrastructure, not this diff:

29513.test.ts has never failed in any shard across any of these builds. No unresolved review threads; claude[bot] LGTM ×5, coderabbit no actionable comments.

@robobun
robobun force-pushed the farm/41279135/asyncdisposablestack-regression-test branch from ea9fa57 to c6a9ad2 Compare April 22, 2026 00:47

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only regression coverage for already-fixed JSC bugs.

Extended reasoning...

Overview

This PR adds a single new file, test/regression/issue/29513.test.ts, containing four regression tests for AsyncDisposableStack behavior (sequential awaiting of use/adopt/defer disposers, and Symbol.dispose fallback). No production code is touched — the underlying bugs were already fixed by a prior JavaScriptCore upgrade (#28371), and this PR just locks in coverage so a future WebKit bump can't silently regress them.

Security risks

None. This is a pure test addition with no runtime, build, or dependency changes.

Level of scrutiny

Low. Test-only changes in test/regression/issue/ follow an established pattern in this repo. The tests are well-constructed: they use Promise.withResolvers() for deterministic control flow rather than timing-based sleeps, and the assertions correctly reflect spec-mandated LIFO sequential disposal semantics. The one Bun.sleep(0) per step is used only to drain microtasks after resolving a deferred promise, which is the standard idiom and not flaky.

Other factors

The bug-hunting system found no issues, CodeRabbit had no actionable comments, and the prior CI failures were confirmed as unrelated flakes (fixed on main by #29559) — robobun reports the new test file itself passed 4/4. There are no outstanding reviewer comments and no CODEOWNERS implications for a new test file.

@robobun
robobun force-pushed the farm/41279135/asyncdisposablestack-regression-test branch from c6a9ad2 to dbbc50b Compare April 22, 2026 02:51

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — well-constructed regression tests with deterministic promise control, no production code changes.

Extended reasoning...

Overview

This PR adds a single new file, test/regression/issue/29513.test.ts, containing four regression tests for AsyncDisposableStack covering #29513 (disposeAsync not awaiting each resource's promise) and #24277 (use() not falling back to Symbol.dispose). Both bugs were already fixed by a JavaScriptCore upgrade; this PR only adds coverage to catch future regressions. No production/runtime code is touched.

Security risks

None. Test-only change with no I/O, no network, no filesystem, no auth/crypto surface.

Level of scrutiny

Low. This is a self-contained test file in test/regression/issue/. The tests are deterministic — they use Promise.withResolvers() to gate resolution explicitly rather than relying on timing/sleeps for correctness, and they assert exact event ordering per the TC39 explicit-resource-management spec (LIFO sequential disposal). The one Bun.sleep(0) is used only to flush microtasks after a manual resolve(), which is a standard pattern and not load-sensitive.

Other factors

  • 4/4 tests pass locally under ASAN per the author's verification on the rebased HEAD.
  • The CI failure (fs.test.ts on Windows) is a pre-existing regression from #29545's unified-sources change leaking S_IFBLK/S_IFSOCK defines — unrelated to this test-only PR and reproduces on #29545's own CI.
  • No CODEOWNERS-sensitive paths, no outstanding human reviewer comments, and the bug-hunting system found no issues.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/regression/issue/29513.test.ts`:
- Line 51: The test uses timing-based scheduler yields (await Bun.sleep(0))
which makes it flaky; replace every call to Bun.sleep(0) in this test with a
deterministic microtask checkpoint such as await Promise.resolve() (or await new
Promise(r => queueMicrotask(r))) so the Promise.withResolvers sequencing remains
stable; search for the Bun.sleep(0) call sites in the test (the Bun.sleep call
expressions) and replace them with await Promise.resolve() to eliminate
setTimeout-style scheduling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e7717f9b-cf3d-4ad1-9d27-ddc32dadad1b

📥 Commits

Reviewing files that changed from the base of the PR and between c6a9ad21f5ff11e8e91ca629e08e62be915d67ff and dbbc50bfd6c12e215c73199fa5590fa41b2d7950.

📒 Files selected for processing (1)
  • test/regression/issue/29513.test.ts

Comment thread test/regression/issue/29513.test.ts Resolved
@robobun
robobun force-pushed the farm/41279135/asyncdisposablestack-regression-test branch from dbbc50b to b58bc82 Compare April 22, 2026 09:27

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only addition with deterministic assertions and no production code changes.

Extended reasoning...

Overview

This PR adds a single new file, test/regression/issue/29513.test.ts, containing four regression tests for AsyncDisposableStack behavior (sequential awaiting in disposeAsync() for use/adopt/defer, and the Symbol.dispose fallback). No production code is touched — both underlying bugs were already fixed by a prior JavaScriptCore upgrade (#28371), and this PR just locks in coverage.

Security risks

None. Pure test code with no I/O, no subprocess spawning, no network, no filesystem writes, and no external inputs. There is nothing security-sensitive here.

Level of scrutiny

Low. This is a self-contained test file in test/regression/issue/ following the repo's standard regression-test conventions. The tests use Promise.withResolvers() for explicit resolution control and Bun.sleep(0) as a macrotask barrier — the latter was questioned by CodeRabbit and convincingly justified (a single microtask hop is insufficient and would couple the test to JSC's internal .then() chain depth); that thread is resolved. No CODEOWNERS entry covers this path.

Other factors

The bug-hunting system found no issues. CI confirms 4/4 tests pass on the rebased HEAD, and earlier CI failures were confirmed unrelated (Windows fs.constants and install-test flakes, both fixed on main). The test logic correctly asserts LIFO ordering and that disposeAsync() remains pending until each disposer's promise resolves, which is exactly the spec behavior being guarded. Straightforward and low-risk.

The underlying JSC bug — GetDisposeMethod wrapped [Symbol.asyncDispose]
in a closure that discarded the returned promise — was fixed upstream
in WebKit and picked up in Bun 1.3.12 via the bump to fc9f2fa7 (#28371).
This adds a regression test so a future WebKit update can't silently
reintroduce the behavior.

Covers use(), adopt(), and defer(); asserts LIFO ordering, that each
disposer is fully awaited before the next begins, and that disposeAsync()
does not resolve until all resources have finished disposing.
@Jarred-Sumner
Jarred-Sumner force-pushed the farm/41279135/asyncdisposablestack-regression-test branch from b58bc82 to 47e4e27 Compare May 4, 2026 10:36

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only regression coverage for already-fixed JSC AsyncDisposableStack bugs.

Extended reasoning...

Overview

This PR adds a single new file, test/regression/issue/29513.test.ts, containing four regression tests for AsyncDisposableStack behavior: sequential LIFO awaiting via use(), awaiting adopt() callbacks, fallback from Symbol.asyncDispose to Symbol.dispose (#24277), and awaiting defer() callbacks. No production/runtime code is modified — both underlying bugs were already fixed by a prior WebKit/JSC upgrade (#28371, Bun 1.3.12), and this PR just locks the behavior in.

Security risks

None. Test-only addition with no I/O, network, filesystem, or subprocess interaction; it exercises pure in-process JS semantics of a TC39 builtin.

Level of scrutiny

Low. The change is additive and isolated to test/regression/issue/. The tests are deterministic: they use Promise.withResolvers() to gate each disposal step and await Bun.sleep(0) only as a macrotask barrier to drain pending microtasks (not as a wall-clock wait). The Bun.sleep(0) concern raised by CodeRabbit was discussed inline and resolved — replacing it with Promise.resolve() would couple the test to JSC's internal .then() hop count and actually break the assertions.

Other factors

CI build #47212 passed on 266 jobs; the single failure (test-worker-nested-uncaught.js on x64-asan) is an unrelated worker-termination race, and the new test file passed in every shard that ran it. The bug-hunting system found no issues. The test logic correctly asserts LIFO ordering (r3→r2→r1), that disposeAsync() remains pending until each resource's promise resolves, and that sync-only disposables don't throw at use().

@robobun
robobun force-pushed the farm/41279135/asyncdisposablestack-regression-test branch from 47e4e27 to dad40ff Compare May 4, 2026 12:52

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only regression coverage for an already-fixed JSC bug.

Extended reasoning...

Overview

This PR adds a single new file, test/regression/issue/29513.test.ts, containing four regression tests for AsyncDisposableStack behavior (use(), adopt(), defer(), and the Symbol.dispose fallback for #24277). No production/runtime code is touched — the underlying bugs were already fixed by a prior JavaScriptCore upgrade (#28371), and this PR only adds coverage to guard against future WebKit regressions.

Security risks

None. The change is pure test code: no auth, crypto, network, filesystem, or subprocess interaction. It exercises in-process JS spec behavior with synthetic resources built from Promise.withResolvers().

Level of scrutiny

Low. Test-only additions to test/regression/issue/ carry minimal blast radius — worst case is a flaky or incorrect test, not a runtime regression. The test design is deterministic (explicit deferred resolution + Bun.sleep(0) as a macrotask barrier rather than wall-clock waits), and the assertions match the TC39 DisposeResources spec (LIFO, sequential awaiting). The PR description verifies the tests fail on 1.3.11 and pass on 1.3.12+/HEAD, confirming they actually catch the regression.

Other factors

The only review feedback (CodeRabbit's suggestion to replace Bun.sleep(0) with Promise.resolve()) was discussed and resolved in-thread with a sound rationale, and CodeRabbit retracted. CI build #47212 is green aside from one unrelated worker-termination flake. The bug-hunting system found no issues. Given the small, self-contained, test-only scope with no outstanding reviewer concerns, this is safe to approve without further human review.

The same GetDisposeMethod rewrite in WebKit that fixed #29513 also fixed
the sync-dispose fallback path (#24277). Add a regression test so a
future WebKit bump can't silently regress it.
@robobun
robobun force-pushed the farm/41279135/asyncdisposablestack-regression-test branch from dad40ff to 115279e Compare May 4, 2026 13:16

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only regression coverage for already-fixed JSC AsyncDisposableStack bugs.

Extended reasoning...

Overview

This PR adds a single new file, test/regression/issue/29513.test.ts, containing four regression tests for AsyncDisposableStack behavior (sequential LIFO awaiting in use()/adopt()/defer(), plus fallback to Symbol.dispose when Symbol.asyncDispose is absent). No production/runtime code is touched — both underlying bugs (#29513, #24277) were already fixed by the WebKit upgrade in #28371; this PR only adds coverage to guard against future JSC regressions.

Security risks

None. Pure in-process test code with no I/O, network, filesystem, subprocess, auth, or crypto surface. The tests construct plain JS objects and promises and assert on an event-order array.

Level of scrutiny

Low. Test-only addition under test/regression/issue/ with no CODEOWNERS coverage. The tests use Promise.withResolvers() for deterministic sequencing and Bun.sleep(0) as a macrotask barrier to drain the microtask queue — the latter was flagged by CodeRabbit but the author explained (and CodeRabbit accepted) that it is deterministic and avoids coupling to JSC's internal .then() hop count; that thread is resolved. The assertions match the TC39 explicit-resource-management spec semantics (synchronous start of the first LIFO disposer, each subsequent disposer beginning only after the prior one's promise settles).

Other factors

The author verified the tests fail on Bun 1.3.11 (reproducing both bugs) and pass on 1.3.12+, HEAD, and bun bd. CI history shows the new file passing in every shard that ran it; prior build failures were unrelated infrastructure/flake issues. No bugs were found by the bug-hunting system, and there are no outstanding unresolved review comments.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only regression coverage for already-fixed JSC bugs.

Extended reasoning...

Overview

This PR adds a single new file, test/regression/issue/29513.test.ts, containing four regression tests for AsyncDisposableStack: sequential LIFO awaiting via use(), adopt(), defer(), and the Symbol.dispose fallback path (#24277). There are zero changes to src/ — the underlying bugs were fixed by a prior WebKit upgrade (#28371), and this PR only locks in coverage.

Security risks

None. Pure test code exercising standard ECMAScript AsyncDisposableStack semantics in-process. No subprocess spawning, no network, no filesystem, no auth/crypto/permissions surfaces.

Level of scrutiny

Low. This is an additive, test-only change in test/regression/issue/. Worst-case failure mode is a flaky or incorrect test, not a runtime regression. The test design is deterministic (explicit Promise.withResolvers() gating each disposal step, Bun.sleep(0) as a macrotask barrier rather than a wall-clock wait), and the PR description documents verification on 1.3.11 (fails as expected) and 1.3.12+/HEAD (passes).

Other factors

  • The only reviewer concern (CodeRabbit's suggestion to replace Bun.sleep(0) with Promise.resolve()) was addressed with a correct rationale and the thread is resolved.
  • robobun reports 4/4 passing across all CI shards that ran the file in builds #47006–#51253.
  • No prior claude[bot] reviews exist on this PR.
  • File placement and naming follow the repo's test/regression/issue/{N}.test.ts convention.

@robobun

robobun commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator Author

Stale PR review: keep open, rework.

The coverage is wanted. Main has no behavioural test for AsyncDisposableStack. git grep -i asyncdisposablestack origin/main -- test/ matches only the global-name list in test/js/node/test/common/globals.js. The tests are real pins. On bun 1.3.0 and 1.3.11, three of the four fail: use, adopt, and the Symbol.dispose fallback ("@@asyncDispose must be callable"). On bun 1.4.3 all four pass.

The location is the problem. CLAUDE.md and test/CLAUDE.md:153 reserve test/regression/issue/ for behaviour that worked in a release and then broke (#29560). Bun 1.2.23 has no AsyncDisposableStack global, and 1.3.0, the first release with it, already fails these tests. The behaviour was never correct, so the tests belong in the existing file for the module. That file is test/js/web/explicit-resource-management.test.ts. Its first line reads "tbh, we should have more tests for this".

Wanted shape:

  • Move the four tests into test/js/web/explicit-resource-management.test.ts as one describe("AsyncDisposableStack") block. Delete test/regression/issue/29513.test.ts.
  • Keep tests 1 to 3 as they are. Test 4 (defer) also passes on 1.3.0 and 1.3.11, so describe it as coverage, not as a pin for AsyncDisposableStack does not correctly await the disposal of each resource #29513.
  • Remove the Closes #29513 and Closes #24277 lines from the description. Both issues are already closed.
  • Merge main. The head (8ef2b1f) dates from 2026-06-16, and no test job ran on it: build #62951 failed after 38 seconds.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants