Skip to content

test(http): speed up and de-flake serve-async-stream-client-abort.test.ts - #35919

Merged
Jarred-Sumner merged 1 commit into
mainfrom
farm/4fa2c41d/speed-up-serve-async-stream-abort-test
Jul 30, 2026
Merged

Jarred-Sumner merged 1 commit into
mainfrom
farm/4fa2c41d/speed-up-serve-async-stream-abort-test

Conversation

@robobun

@robobun robobun commented Jul 26, 2026 •

Copy link
Copy Markdown
Collaborator

What

Cuts test/js/bun/http/serve-async-stream-client-abort.test.ts from ~14 s to ~6 s under debug+ASAN and fixes a pre-existing ~30% flake in the error-stream fixture.

Why it was slow

The file runs three tests, each spawning a fixture subprocess. Under debug+ASAN a bun-debug startup is ~1.5 s, and the native-stream fixture spawns three more bun-debug children just to obtain a stalled stdout pipe. That is six ASAN startups in series.

Changes

  • All three tests run concurrently. Each owns an independent subprocess with its own port: 0 server, so there is no shared state.
  • native-stream fixture uses cat for the stalled child on posix. The test only needs a subprocess stdout pipe (native-source ReadableStream) that emits one byte and then blocks. cat with a piped stdin is that, without a JS runtime boot per iteration. Windows keeps a bun child (process.stdin.pipe(process.stdout)): there is no cat there and no ASAN lane, so startup cost is not the bottleneck. Fixture time under ASAN: 4.2 s → 0.5 s.
  • error-stream fixture waits for req.signal instead of Bun.sleep(1). The abort-path loop released the parked producer after resetAndDestroy() plus a 1 ms sleep and hoped the server had processed the RST by then. On a loaded box the first iteration's late enqueue() often landed on a still-live sink and reported "ok" instead of the expected closed-controller error (4/30 solo runs, 5/15 runs of the unmodified test file on current main). req.signal's abort event is the server-side observation point, so the driver now awaits it before releasing: 0/40 solo runs, 0/20 full-file runs after.
  • Assertions parse the fixture JSON. Each test now checks the actual payload (lateCloseResults entries, aborted/completed counts, aborted: 3) instead of expect.stringContaining('"ok":true'), and asserts stderr/exitCode/signalCode separately so a failure names the field.

Coverage

No tests removed or skipped. Iteration counts are unchanged. The native-stream repro mechanism is unchanged: the Response body is still a subprocess stdout pipe, which is the native-source ReadableStream path the original UAF was on.

Timing (local, debug+ASAN)

before: Ran 3 tests across 1 file. [13.88s]   (wall 15.3 s)
after:  Ran 3 tests across 1 file. [ 6.20s]   (wall  6.5 s, 20/20 consecutive passes)

[stamp-90s] gate passed · iteration 0 · 3 files touched

passes on PR (with fix)
Test-only change.

Debug/ASAN (expected pass):
$ bun bd test 'test/js/bun/http/serve-async-stream-client-abort.test.ts'
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test test/js/bun/http/serve-async-stream-client-abort.test.ts
bun test v1.4.0 (f73ce7dbe)

test/js/bun/http/serve-async-stream-client-abort.test.ts:
(pass) client aborting a native-source stream response does not use the sink after free [424.01ms]
(pass) streaming error() response from an async-rejecting fetch is not ended by render_missing [1678.21ms]
(pass) client aborting an async-pull ReadableStream response does not crash the server [2611.49ms]

 3 pass
 0 fail
 11 expect() calls
Ran 3 tests across 1 file. [4.72s]
Exit: 0
diff hotspot
.../http/serve-async-stream-client-abort.test.ts   | 100 +++++++++++----------
 .../serve-error-stream-client-abort-fixture.ts     |  32 ++++---
 .../serve-native-stream-client-abort-fixture.ts    |  15 ++--
 3 files changed, 81 insertions(+), 66 deletions(-)

gate history · 1 passed · 0 rejected · iteration 0

evidence per changed file
file                                                      reads  edits  tests
test/js/bun/http/serve-async-stream-client-abort.test.ts      1      1      0
…/js/bun/http/serve-error-stream-client-abort-fixture.ts      2      2      0
…js/bun/http/serve-native-stream-client-abort-fixture.ts      2      1      0

self-review · no surviving concerns

29 concerns were raised and did not survive verification.

…t.ts

The three tests each spawn an independent fixture subprocess; running
them concurrently overlaps the debug/ASAN startup instead of paying it
three times in series.

The native-stream fixture spawned three more bun-debug children just to
get a stalled stdout pipe, which under ASAN is ~1.5 s of startup each.
cat with a piped stdin is the same native-source ReadableStream without
the JS runtime boot (Windows keeps a bun child since cat is posix-only
and there is no ASAN lane there).

The error-stream fixture raced Bun.sleep(1) against the server seeing
the client's RST, so the first abort iteration intermittently reported
the late enqueue as "ok" instead of the expected closed-controller
error. Waiting on req.signal's abort event makes the sequencing
deterministic.

Assertions now parse the fixture JSON and check the actual fields
(lateCloseResults contents, aborted/completed counts) rather than
scanning for an ok:true substring.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6a179b13-0014-4013-b6ae-983890573bf3

📥 Commits

Reviewing files that changed from the base of the PR and between 44f6469 and f73ce7d.

📒 Files selected for processing (3)
  • test/js/bun/http/serve-async-stream-client-abort.test.ts
  • test/js/bun/http/serve-error-stream-client-abort-fixture.ts
  • test/js/bun/http/serve-native-stream-client-abort-fixture.ts

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

@robobun

robobun commented Jul 26, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 8:27 AM PT - Jul 26th, 2026

❌ @robobun, your commit f73ce7d has 1 failures in Build #82354 (All Failures):

  • 📦 Binary size — 12 over 0.50 MB
  • targetthis build canary: main #79916
    sizeΔ
    ❌ bun-darwin-aarch6458.13 MB57.58 MB+564.9 KB
    ❌ bun-darwin-x6463.48 MB62.95 MB+544.5 KB
    ❌ bun-linux-aarch6470.98 MB70.42 MB+576.0 KB
    ❌ bun-linux-x6472.47 MB71.95 MB+528.0 KB
    ❌ bun-linux-aarch64-musl64.88 MB64.32 MB+576.0 KB
    ❌ bun-linux-x64-musl66.98 MB66.45 MB+544.0 KB
    ❌ bun-linux-aarch64-android78.47 MB77.97 MB+512.0 KB
    ❌ bun-linux-x64-android80.62 MB80.10 MB+529.2 KB
    ❌ bun-freebsd-x6483.07 MB82.56 MB+528.0 KB
    ❌ bun-freebsd-aarch6484.84 MB84.31 MB+544.0 KB
    ❌ bun-windows-x6480.26 MB79.70 MB+570.5 KB
    ❌ bun-windows-aarch6470.86 MB70.34 MB+533.0 KB

    Add [skip size check] to the commit message if this increase is intentional.


🧪   To try this PR locally:

bunx bun-pr 35919

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

bun-35919 --bun

@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 speedup and de-flake, no production code touched.

What was reviewed:

  • test.concurrent is safe: each fixture owns an independent subprocess with its own port: 0 server.
  • error-stream: once(s, "data") still rejects on pre-data socket errors; the post-RST error swallow only covers the client-side ECONNRESET from resetAndDestroy(). currentSignal is set in fetch() before error()'s pull resolves started, so no ordering race.
  • native-stream: the removed 30s child backstop is replaced by pipe-EOF — when the parent dies, cat / process.stdin.pipe(process.stdout) see stdin close and exit, so no orphans on a crashed run. The Response body is still a subprocess stdout pipe, so the native-source ReadableStream UAF path is unchanged.
  • New completed + aborted === 600 assertion matches the unmodified async-stream fixture's WORKERS * ITERATIONS.
Extended reasoning...

Overview

Touches three test files only: serve-async-stream-client-abort.test.ts and two of its fixtures. Converts the three tests to test.concurrent, extracts a shared runFixture helper, replaces expect.stringContaining('"ok":true') with parsed-JSON assertions, swaps the native-stream fixture's stalled child from a nested bun-debug to cat (posix) / process.stdin.pipe(process.stdout) (win32), and replaces the error-stream fixture's Bun.sleep(1) race with an await on req.signal's abort event.

Security risks

None. Test-only; no new external inputs, no network beyond loopback, no new dependencies.

Level of scrutiny

Low-to-moderate. No runtime code changes. The main risk with test speedup/de-flake PRs is silently weakening coverage, so I checked each change against that:

  • Concurrency: fixtures are hermetic subprocesses — no shared state.
  • cat swap: the property under test is "client abort while a native-source ReadableStream (subprocess stdout pipe) has a pull in flight". Any subprocess stdout pipe exercises that path; the child's runtime is irrelevant. Windows keeps a bun child so no reliance on a posix binary there.
  • req.signal await: this is the repo-recommended "await the actual observable condition" pattern replacing a 1 ms sleep. It strictly tightens the sequencing the original test intended.
  • Assertions: strictly stronger than before (exact lateCloseResults shape, aborted: 3, completed + aborted === 600). Verified the unmodified serve-async-stream-client-abort-fixture.ts emits {ok, completed, aborted} with 20×30 iterations.

Other factors

  • The removed 30 s backstop timer in the old bun child is no longer needed: both cat and the win32 stdin-pipe child exit on stdin EOF when the parent dies, so orphans are still prevented on a crashed run.
  • once() from node:events on an AbortSignal (EventTarget) and child.stdin.flush() on a spawn FileSink are both established patterns elsewhere in test/.
  • s.on("error", () => {}) looks like a swallow but only covers the expected client-side ECONNRESET after resetAndDestroy(); once(s, "data") still rejects on a genuine pre-data connection error via its internal error listener.
  • No prior human reviews; CI build was still running at review time.

@robobun

robobun commented Jul 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finished: serve-async-stream-client-abort.test.ts passed on all 195 test lanes (linux, alpine, debian, ubuntu, windows x64/aarch64, darwin 14 x64/aarch64, darwin 26 aarch64). The only hard failure is binary-size, which compares against canary main #79916 and flags ~550 KB growth on every target; this diff touches three .ts test files and zero compiled code, so that is baseline drift from main and a retrigger would not change it. All other reds are flakes that passed on retry (no-orphans, bun-install-registry, test-http-server-connections-checking-leak, require-cache, 20144), none in files this PR touches.

Ready for review.

@Jarred-Sumner
Jarred-Sumner merged commit 9a568e7 into main Jul 30, 2026
53 of 55 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the farm/4fa2c41d/speed-up-serve-async-stream-abort-test branch July 30, 2026 02:53
hughescr added a commit to hughescr/bun that referenced this pull request Jul 31, 2026
* upstream/main: (422 commits)
  install: drop packages held only by optional-peer resolution slots from bun.lock (oven-sh#35681)
  Update mimalloc to the upstream dev3 (v3.4.3) sync (oven-sh#36431)
  compile(pe): ftruncate the Windows --compile output after writing (oven-sh#36430)
  Strong: back bun_jsc::Strong with StrongRootBlock; free AbortSignal.timeout at wrapper GC (oven-sh#35849)
  test(harness): replace toRun matcher with async bunRun + toSpawn (oven-sh#36424)
  test: measure memory via harness rss() instead of process.memoryUsage.rss() (oven-sh#36429)
  Deflake a few tests
  no-orphans(windows): allow CREATE_BREAKAWAY_FROM_JOB and set DIE_ON_UNHANDLED_EXCEPTION on the Job (oven-sh#36414)
  GarbageCollectionController: replace per-tick heap sampler with idle timer only (oven-sh#35356)
  exe_format(pe): write a valid OptionalHeader.CheckSum for --compile output (oven-sh#36383)
  FileSink: flush buffered bytes when process.exit() runs in the same tick as write() (oven-sh#36250)
  test(http): speed up and de-flake serve-async-stream-client-abort.test.ts (oven-sh#35919)
  test(20144): stop racing child startup against the 1s SIGKILL guard (oven-sh#34166)
  test(no-orphans): skip fast-exit perl daemon test on macOS (oven-sh#36413)
  fs: return negative BigIntStats *Ns for pre-epoch timestamps (oven-sh#36187)
  event_loop: make DeferredTaskQueue::run tolerate re-entrant map mutation (oven-sh#32703)
  dotenv: stop panicking on nested `${...}` inside `${VAR:-default}` (oven-sh#36199)
  fetch: make the idle timer an absolute deadline for the response header block (oven-sh#36145)
  bundler: don't panic on unterminated naming template placeholders (oven-sh#36325)
  Buffer#indexOf/lastIndexOf: rare-byte SIMD filter with a Two-Way O(n+m) fallback (oven-sh#36420)
  ...

# Conflicts:
#	src/jsc/bindings/BunDebugger.cpp
hughescr added a commit to hughescr/bun that referenced this pull request Jul 31, 2026
* upstream/main: (422 commits)
  install: drop packages held only by optional-peer resolution slots from bun.lock (oven-sh#35681)
  Update mimalloc to the upstream dev3 (v3.4.3) sync (oven-sh#36431)
  compile(pe): ftruncate the Windows --compile output after writing (oven-sh#36430)
  Strong: back bun_jsc::Strong with StrongRootBlock; free AbortSignal.timeout at wrapper GC (oven-sh#35849)
  test(harness): replace toRun matcher with async bunRun + toSpawn (oven-sh#36424)
  test: measure memory via harness rss() instead of process.memoryUsage.rss() (oven-sh#36429)
  Deflake a few tests
  no-orphans(windows): allow CREATE_BREAKAWAY_FROM_JOB and set DIE_ON_UNHANDLED_EXCEPTION on the Job (oven-sh#36414)
  GarbageCollectionController: replace per-tick heap sampler with idle timer only (oven-sh#35356)
  exe_format(pe): write a valid OptionalHeader.CheckSum for --compile output (oven-sh#36383)
  FileSink: flush buffered bytes when process.exit() runs in the same tick as write() (oven-sh#36250)
  test(http): speed up and de-flake serve-async-stream-client-abort.test.ts (oven-sh#35919)
  test(20144): stop racing child startup against the 1s SIGKILL guard (oven-sh#34166)
  test(no-orphans): skip fast-exit perl daemon test on macOS (oven-sh#36413)
  fs: return negative BigIntStats *Ns for pre-epoch timestamps (oven-sh#36187)
  event_loop: make DeferredTaskQueue::run tolerate re-entrant map mutation (oven-sh#32703)
  dotenv: stop panicking on nested `${...}` inside `${VAR:-default}` (oven-sh#36199)
  fetch: make the idle timer an absolute deadline for the response header block (oven-sh#36145)
  bundler: don't panic on unterminated naming template placeholders (oven-sh#36325)
  Buffer#indexOf/lastIndexOf: rare-byte SIMD filter with a Two-Way O(n+m) fallback (oven-sh#36420)
  ...
hughescr added a commit to hughescr/bun that referenced this pull request Jul 31, 2026
* upstream/main: (422 commits)
  install: drop packages held only by optional-peer resolution slots from bun.lock (oven-sh#35681)
  Update mimalloc to the upstream dev3 (v3.4.3) sync (oven-sh#36431)
  compile(pe): ftruncate the Windows --compile output after writing (oven-sh#36430)
  Strong: back bun_jsc::Strong with StrongRootBlock; free AbortSignal.timeout at wrapper GC (oven-sh#35849)
  test(harness): replace toRun matcher with async bunRun + toSpawn (oven-sh#36424)
  test: measure memory via harness rss() instead of process.memoryUsage.rss() (oven-sh#36429)
  Deflake a few tests
  no-orphans(windows): allow CREATE_BREAKAWAY_FROM_JOB and set DIE_ON_UNHANDLED_EXCEPTION on the Job (oven-sh#36414)
  GarbageCollectionController: replace per-tick heap sampler with idle timer only (oven-sh#35356)
  exe_format(pe): write a valid OptionalHeader.CheckSum for --compile output (oven-sh#36383)
  FileSink: flush buffered bytes when process.exit() runs in the same tick as write() (oven-sh#36250)
  test(http): speed up and de-flake serve-async-stream-client-abort.test.ts (oven-sh#35919)
  test(20144): stop racing child startup against the 1s SIGKILL guard (oven-sh#34166)
  test(no-orphans): skip fast-exit perl daemon test on macOS (oven-sh#36413)
  fs: return negative BigIntStats *Ns for pre-epoch timestamps (oven-sh#36187)
  event_loop: make DeferredTaskQueue::run tolerate re-entrant map mutation (oven-sh#32703)
  dotenv: stop panicking on nested `${...}` inside `${VAR:-default}` (oven-sh#36199)
  fetch: make the idle timer an absolute deadline for the response header block (oven-sh#36145)
  bundler: don't panic on unterminated naming template placeholders (oven-sh#36325)
  Buffer#indexOf/lastIndexOf: rare-byte SIMD filter with a Two-Way O(n+m) fallback (oven-sh#36420)
  ...

# Conflicts:
#	src/js/internal/debugger.ts
hughescr added a commit to hughescr/bun that referenced this pull request Jul 31, 2026
* upstream/main: (422 commits)
  install: drop packages held only by optional-peer resolution slots from bun.lock (oven-sh#35681)
  Update mimalloc to the upstream dev3 (v3.4.3) sync (oven-sh#36431)
  compile(pe): ftruncate the Windows --compile output after writing (oven-sh#36430)
  Strong: back bun_jsc::Strong with StrongRootBlock; free AbortSignal.timeout at wrapper GC (oven-sh#35849)
  test(harness): replace toRun matcher with async bunRun + toSpawn (oven-sh#36424)
  test: measure memory via harness rss() instead of process.memoryUsage.rss() (oven-sh#36429)
  Deflake a few tests
  no-orphans(windows): allow CREATE_BREAKAWAY_FROM_JOB and set DIE_ON_UNHANDLED_EXCEPTION on the Job (oven-sh#36414)
  GarbageCollectionController: replace per-tick heap sampler with idle timer only (oven-sh#35356)
  exe_format(pe): write a valid OptionalHeader.CheckSum for --compile output (oven-sh#36383)
  FileSink: flush buffered bytes when process.exit() runs in the same tick as write() (oven-sh#36250)
  test(http): speed up and de-flake serve-async-stream-client-abort.test.ts (oven-sh#35919)
  test(20144): stop racing child startup against the 1s SIGKILL guard (oven-sh#34166)
  test(no-orphans): skip fast-exit perl daemon test on macOS (oven-sh#36413)
  fs: return negative BigIntStats *Ns for pre-epoch timestamps (oven-sh#36187)
  event_loop: make DeferredTaskQueue::run tolerate re-entrant map mutation (oven-sh#32703)
  dotenv: stop panicking on nested `${...}` inside `${VAR:-default}` (oven-sh#36199)
  fetch: make the idle timer an absolute deadline for the response header block (oven-sh#36145)
  bundler: don't panic on unterminated naming template placeholders (oven-sh#36325)
  Buffer#indexOf/lastIndexOf: rare-byte SIMD filter with a Two-Way O(n+m) fallback (oven-sh#36420)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants