Skip to content

io: POSIX pipe writers hold a ref on their parent from on_error until close() returns - #34697

Closed
robobun wants to merge 7 commits into
mainfrom
farm/52c8d90b/shell-iowriter-error-path-hardening
Closed

robobun wants to merge 7 commits into
mainfrom
farm/52c8d90b/shell-iowriter-error-path-hardening

Conversation

@robobun

@robobun robobun commented Jul 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • A script pipes a type: "direct" ReadableStream into stdout with Bun.write and awaits controller.flush(). The reader exits. An ASAN build reports heap-use-after-free in PosixStreamingWriter<FileSink>::close (src/io/PipeWriter.rs:1076), called from _on_error.
  • _on_error calls Parent::on_error, then self.close(). FileSink::on_error rejects the flush promise, and the rejection handlers release the last refs on the sink. The writer is a field of the sink.

Fix

  • Both POSIX pipe writers hold a ref on the parent across on_error and close(): in _on_error, and in the failed-registration arm of PosixStreamingWriter::register_poll. Nothing uses the writer after close().
  • ParentKeepAlive is the RAII guard. The parent macros stamp its trait, PosixWriterParent, from the ref_ and deref that each parent already passes for Windows. The arm of register_poll is a #[cold] function, so register_poll still inlines into write.
  • Verified: test/js/bun/util/filesink.test.ts (main's ASAN build fails the new test). Also the terminal, shell and spawn suites.
  • Self-reviewed: 3 concerns raised, 3 addressed (see Notes).

Background

  • A pipe writer drains bytes to an fd and reports to its refcounted parent (FileSink, Terminal, the shell IOWriter, StaticPipeWriter) through on_write, on_error and on_close.
  • Bun.write(dest, stream) pumps into a FileSink with no JS wrapper. Two refs hold it: the pump's, and a keep-alive ref that on_close releases.
  • Considered a guard inside FileSink::on_error: it ends before the writer calls close(). The writer's guard covers every parent.

Downsides

  • A failed write costs one more increment and decrement of the parent's refcount.
  • A write that succeeds costs nothing new: 346 instructions in FileSink::write for a 64-byte write, on main and here. Text grows by 768 bytes.
  • Not changed: the Windows writers, and uses of a writer after on_write (see Notes).
Notes

This is a rebase of the July version of this PR. What changed in it:

Repro (Linux x64, debug ASAN build):

cat > sink.mjs <<'JS'
await Bun.write(Bun.stdout, new Response(new ReadableStream({ type: "direct",
  async pull(c) { c.write(new Uint8Array(1 << 20)); await c.flush(); c.close(); } })));
JS
bun sink.mjs | (sleep 0.1; head -c 262144 > /dev/null)

main at 11c41c6: 3 of 3 runs report the use-after-free. This branch: 0 of 3, exit status 1 with one EPIPE: broken pipe, write, the same as a release build.

heap-use-after-free, READ of size 1, 121 bytes inside of a 344-byte region
 #0 PosixStreamingWriter<FileSink>::close       src/io/PipeWriter.rs:1076
 #1 PosixStreamingWriter<FileSink>::_on_error   src/io/PipeWriter.rs:790
 #3 PosixPipeWriter::on_poll                    src/io/PipeWriter.rs:202
freed by
#17 FileSink::run_pending                       src/runtime/webcore/FileSink.rs:362
#18 FileSink::on_error                          src/runtime/webcore/FileSink.rs:483
#20 PosixStreamingWriter<FileSink>::_on_error   src/io/PipeWriter.rs:789

How the last ref goes away inside on_error. run_pending rejects the flush promise and runs the microtasks. pull() rejects, so the promise of the pump rejects and on_reject_stream runs. It adopts the ref of the pump and calls handle_reject_stream, which calls writer.close(). _on_error already closed the fd without a report, so this close() delivers on_close, and on_close releases the keep-alive ref. on_reject_stream then drops the ref of the pump, and the guard in run_pending drops the last one.

With the change the close() at the end of _on_error finds the handle closed and reports nothing. The sink gets one on_error and one on_close. In the release build the flag closed_without_reporting is read from memory again after the on_error call (checked in the disassembly of __bun_run_file_poll), so a value from before the call is not used. The guard is three instructions there: incl, then decl and jne in front of the cold call that frees the sink.

Cost of a write that succeeds. register_poll runs on every buffered write. With the guard inline in its error arm, the compiler stopped inlining register_poll into write. The arm is out of line now. I counted user instructions from the entry of FileSink::write to its return with gdb (stepi), over 128 consecutive calls, in release builds on the same base (5a183c1). The script writes 64 bytes to proc.stdin in a loop and calls flush() every 64 writes.

build buffered write write that reaches 4096 bytes average
main 346 386 346.6
guard inline in the arm (f29b67c) 363 384 363.3
#[cold] arm (this head) 346 384 346.6

size of the stripped binary: text 80,677,348 on main and 80,678,116 here. Both files are 80,844,360 bytes. perf and valgrind are not available in my container, so I have no count for a whole process.

The test. A write error reaches the sink from two places. One is the poll callback (this bug). The other is the flush that the auto-flusher of the sink makes after each microtask drain. That one has its own guard and does not reach _on_error. So the read end has to close while the child waits in its poll. The test reads 4 x 64 KiB from a FIFO, waits 10 ms, and then closes. Each refill shows that the child ran, and the wait lets it finish the turn that made the last refill. On the debug ASAN build of main the test fails 5 of 5 times alone and 2 of 2 times inside the whole file. The same sequence in a script, 6 at a time, reports the use-after-free 18 of 18 times. A fixed build gives the same output on both paths, so the wait cannot make the test fail there.

An earlier version closed in the same step as its last read. That finds the bug only when the close lands before the next write of the child. A fast build often writes first, and then the flush at the end of that turn reports the error.

Not changed: Windows. The Windows writers take a ref on the parent for each write in flight and release it after the completion callback. That covers this order there. The three arms of WindowsStreamingWriter::process_send for a write that fails at once call on_error and then close() with no ref of their own. I found no way to reach them with a promise pending, and I cannot run Windows.

Not changed: the free under &mut self. The release of the guard can free the parent while _on_error(&mut self) is on the stack. Main already frees at this position (StaticPipeWriter::on_close, FileSink::on_close), and #37755 moves that chain to raw pointers.

Not changed: uses of the writer after on_write. There are nine on POSIX: six in the write* functions of PosixStreamingWriter (on_write, then register_poll), the Pending arm of on_poll for each of the two writers, and PosixBufferedWriter::_on_write (on_write, then close() at end of file). I found no input that frees the parent inside them. Only facts about each parent prevent it, and no written rule does. A guard there adds a ref and a deref to every write. #37755 reworks that chain and is the place for the rule.

Self-review. Three concerns survived, and each is handled. The SAFETY note in StaticPipeWriter::on_close said that its deref frees the writer on POSIX. With the new ref it does not, so the note is updated, and so is the comment in FileSink::on_error. Both POSIX parent traits now say what on_error may release. The unguarded sites are listed above. #37755 rewrites the same three functions: the one that lands second has to carry the ref.

Checks. cargo fmt, cargo clippy for bun_io, bun_spawn and bun_runtime, cargo check for x86_64-pc-windows-msvc and aarch64-apple-darwin. On the debug ASAN build: filesink.test.ts (78 pass), terminal.test.ts (99), console-write.test.ts (5), shell/file-io.test.ts (27), shell-blocking-pipe.test.ts (2), shell-write-fault.test.ts (1), spawn-stdio-syscall-error.test.ts (17), spawn-stdin-readable-stream.test.ts (37), spawn-stdin-pipe-fd-leak.test.ts (4). spawn.test.ts ran on an overloaded host: 170 pass and 8 timeouts at 5 s here, 172 pass and 6 timeouts in the same groups on the build of main.


no test proof · iteration 10 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/bun/util/filesink.test.ts

@robobun

robobun commented Jul 19, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 8:12 AM PT - Oct 1st, 2026

❌ @robobun, your commit 6861b25 has 1 failures in Build #122410 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 34697

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

bun-34697 --bun

@github-actions

Copy link
Copy Markdown
Contributor

Found 3 issues this PR may fix:

  1. --env-file and Bun.file().text() silently drop data on FIFOs; breaks 1Password's local-env-file integration #30520 - --env-file and Bun.file().text() silently drop data on FIFOs; the PR fixes the root cause of FIFO pollable flag being discarded in shell builtin redirections
  2. Bun Shell hangs with git show command, spawnSync from node:child_process succeeds #26580 - Bun Shell hangs with git show command; the pipe buffer filling + incorrect non-pollable routing could cause this class of shell hang
  3. FileSink.write incoherencies #12194 - FileSink.write incoherencies when piping large data; the PR's keepalive hardening of POSIX pipe writer error paths addresses erratic behavior writing to subprocess stdin pipes

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

Fixes #30520
Fixes #26580
Fixes #12194

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

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

Changes

POSIX pipe lifetime and shell I/O

Layer / File(s) Summary
Writer error dispatch and parent lifetime
src/io/PipeWriter.rs
POSIX writers add intrusive parent pinning around error callbacks, propagate buffered errors through polling, and update generated vtable shims.
Terminal parent refcount wiring
src/runtime/api/bun/Terminal.rs
Terminal implements the new POSIX streaming writer refcount hooks.
Pollable shell redirection and callback keepalive
src/runtime/shell/..., test/js/bun/shell/shell-blocking-pipe.test.ts
Shell redirects use detected pollability, callbacks retain IOWriter, subprocess ownership comments are updated, and named-pipe backpressure is covered by a regression test.
Static pipe dispatch and error cleanup
src/runtime/dispatch.rs, src/spawn/static_pipe_writer.rs
Static pipe polling uses an explicit lifetime-safe dispatch wrapper, and non-Windows static pipe errors conditionally release the reference held by start().

DNS poll registration failure

Layer / File(s) Summary
libinfo poll failure completion
src/runtime/dns_jsc/dns.rs
macOS DNS lookup now deinitializes failed poll registration and completes the request with an error callback.

Possibly related PRs

  • oven-sh/bun#34696: Both changes update POSIX FIFO redirection and pollable writer behavior.

Suggested reviewers: jarred-sumner

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly describes the primary change: POSIX pipe writers retain a reference to their parent during error handling until close() completes.
Description check ✅ Passed The description explains the problem, fix, scope, limitations, regression scenario, and verification results. It does not use the exact template headings, but it provides the required information in e…

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

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/dns_jsc/dns.rs`:
- Line 303: Replace the silent `let _ = err` handling in the `register_with_fd`
failure path with a scoped debug log that includes the registration error, then
preserve the existing callback behavior.

In `@test/js/bun/shell/shell-blocking-pipe.test.ts`:
- Around line 67-76: Update the blocking-pipe test’s drained promise around the
reader and process wait: when proc.exited returns a non-zero exit code, destroy
the reader so its error/close path rejects or settles instead of waiting
indefinitely for FIFO EOF. Await the reader completion together with stderr,
stdout, and proc.exited, while preserving successful-exit draining behavior and
wiring reader failure events to rejection.
🪄 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: 6bbbdd85-5983-4bbd-a4c2-78c449bcfffb

📥 Commits

Reviewing files that changed from the base of the PR and between 98f6649 and 28052d4.

📒 Files selected for processing (7)
  • src/io/PipeWriter.rs
  • src/runtime/api/bun/Terminal.rs
  • src/runtime/dns_jsc/dns.rs
  • src/runtime/shell/Builtin.rs
  • src/runtime/shell/IOWriter.rs
  • src/runtime/shell/subproc.rs
  • test/js/bun/shell/shell-blocking-pipe.test.ts

Comment thread src/runtime/dns_jsc/dns.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. shell: route FIFO redirect targets through the pollable IOWriter path #34696 - Both PRs fix the same FIFO redirect panic in Builtin.rs by passing the computed pollable value to IOWriter::init instead of a hardcoded cfg!(windows), and overlap in IOWriter.rs changes

🤖 Generated with Claude Code

Comment thread src/io/PipeWriter.rs Resolved

@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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/js/bun/shell/shell-blocking-pipe.test.ts`:
- Around line 84-91: In the blocking-pipe test, move the exitCode failure check
before the combined expect assertion so child stderr is surfaced when the
process fails. Keep the successful-result assertion focused on stdout and
receivedLen (with exitCode as appropriate), and remove the now-unreachable
post-assertion throw.
🪄 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: 24465161-50cb-455e-b61d-706e4eb9e8fc

📥 Commits

Reviewing files that changed from the base of the PR and between d652eae and d208073.

📒 Files selected for processing (2)
  • src/spawn/static_pipe_writer.rs
  • test/js/bun/shell/shell-blocking-pipe.test.ts

@robobun

robobun commented Jul 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

This comment described the July version of this PR (f0036f3, build #76593). That version is no longer in the PR. The PR was rebased on 2026-09-30 and is now one change. The PR body and the rebase comment describe it.

A correction to what this comment said before:

  • It said that the July test passed on every lane. The test was skipped on Windows. For the POSIX lanes, the pass was inferred from the list of failures.
  • It called the other first-attempt failures flaky before I had read them. Two of the files, filesink.test.ts and spawn-stdin-pipe-fd-leak.test.ts, test the pipe writers that the July version changed. I have read three of those four failures now. They are file descriptor count assertions that passed on retry. I did not find out whether the July diff contributed.

Checked again on 2026-10-01 with the script in the PR body, Linux x64, debug ASAN builds:

  • main at 367d939 (2026-09-18): heap-use-after-free in PosixStreamingWriter<FileSink>::close, called from _on_error, in 3 of 3 runs.
  • this branch at b50d318: exit status 1 with EPIPE: broken pipe, write and no ASAN report, in 3 of 3 runs. I did not run the commits after 0fb95d1.

Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/runtime/dns_jsc/dns.rs Resolved

@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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/dispatch.rs`:
- Around line 704-728: Restore Windows compatibility for the static pipe writer
polling arms in the dispatch match, including STATIC_PIPE_WRITER,
SHELL_STATIC_PIPE_WRITER, and SECURITY_SCAN_STATIC_PIPE_WRITER. Either
conditionally exclude these arms on Windows or provide a Windows
implementation/shim for bun_spawn::static_pipe_writer::on_poll, ensuring all
referenced symbols resolve on every target.
🪄 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: f2fd94e6-1aaa-4ef7-95d6-58e2a6f19bf9

📥 Commits

Reviewing files that changed from the base of the PR and between d208073 and bd159eb.

📒 Files selected for processing (3)
  • src/runtime/dispatch.rs
  • src/spawn/static_pipe_writer.rs
  • test/js/bun/shell/shell-blocking-pipe.test.ts

Comment thread src/runtime/dispatch.rs Resolved
Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/runtime/dispatch.rs Resolved

@Jarred-Sumner Jarred-Sumner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you use an RAII wrapper

@robobun

robobun commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator Author

Done in f0036f3:

  • PosixBufferedWriter/PosixStreamingWriter now have a parent_keepalive() helper that bumps Parent::ref_ and returns a scopeguard whose Drop runs Parent::deref (matching the existing scopeguard::guard(this, |s| Self::r_deref(s)) pattern the Windows writer paths already use). The four call sites are now just let _keepalive = self.parent_keepalive();.
  • static_pipe_writer::on_poll switched to bun_ptr::ScopedRef::new(parent) directly since StaticPipeWriter<P> is #[derive(RefCounted)].

Couldn't use bun_ptr::ScopedRef in PipeWriter.rs itself because the Parent generic is not bounded by AnyRefCounted (the shell IOWriter parent is Arc-backed, not intrusive-refcounted), so the trait-method-based scopeguard is the tight fit there.

Comment thread src/io/PipeWriter.rs Resolved
Jarred-Sumner pushed a commit that referenced this pull request Jul 24, 2026
…n write completes (#35297)

On Windows, `Bun.spawn`/`Bun.spawnSync` with a non-empty
`ArrayBuffer`/`Blob` `stdin` leaked one `StaticPipeWriter` allocation
per spawn.

## Cause

`StaticPipeWriter::start()` takes a `+1` and sets `started = true`.
#30875 added a `release_start_ref` block to `on_write()` that clears
`started` and derefs once the buffer drains, but gated it behind
`#[cfg(not(windows))]`:


https://github.com/oven-sh/bun/blob/892b1dabc6/src/spawn/static_pipe_writer.rs#L228-L241

On Windows, when the `uv_write` completes before the child exits (the
common ordering for a small buffer):

```
on_write_complete(status=0)
  -> Parent::on_write(Pending)             (release_start_ref gated out)
     -> writer.close()
        -> BaseWindowsPipeWriter::close -> on_close_source
           -> StaticPipeWriter::on_close -> Subprocess::on_close_io(Stdin)
              stdin <- Writable::Ignore; buffer.deref()   (create()'s +1)
  scopeguard deref                                         (write()'s +1)
```

Net: `started` is still `true` but `stdin` is `Writable::Ignore`, so the
other release site, `take_pending_start_writer` (called from
`on_process_exit` / `close_io`), matches nothing and start()'s `+1` is
stranded. The error arm of `on_write_complete` (e.g. `ERROR_BROKEN_PIPE`
when the child closes stdin without reading) reaches `on_close` via
`close()` without ever calling `Parent::on_write`, so start()'s `+1` is
stranded there the same way.

`ShellSubprocess` has the same leak for `cmd < ${buf}` stdin since its
`on_process_exit`/`close_io` never look at `started` at all and depend
entirely on `on_write`'s release.

## Fix

- `StaticPipeWriter::on_write`: drop the `cfg(not(windows))` gates so
`release_start_ref` runs on every platform. `WindowsBufferedWriter`
never passes `EndOfFile`, so the existing `status != EndOfFile` guard is
a no-op there and is left for the POSIX path
(`PosixBufferedWriter::_on_write` still touches `self` after the
callback on `EndOfFile`).
- `StaticPipeWriter::on_close` (Windows only): claim `started` and deref
after `on_close_io` for paths that reach `close()` without going through
`on_write` (the `on_write_complete` error arm). `write()`'s +1, held by
that callback's scopeguard, keeps `self` live past the release. This is
gated to Windows because on POSIX `drain_buffered_data` may call
`on_error()` -> `close()` -> `on_close` and then `on_write()` on the
same object with no extra ref held; #34697 changes that ordering and the
gate can go once it lands.
- `Subprocess::take_pending_start_writer`: clear `started` when it
claims the pointer. The three release sites are then mutually exclusive
via `started`, covering the ordering where `on_process_exit` closes the
pipe while a `uv_write` whose I/O already completed is still queued
(libuv delivers that callback with its real status after `uv_close`, not
`ECANCELED`).
- `WindowsBufferedWriter::on_write_complete`: `saturating_sub` for
`has_pending_data` so the late-success-after-close ordering does not
underflow in debug builds.

`SecurityScanSubprocess` already derefs and writes `started = false`
immediately after `start()`, so both new release sites see `started =
false`; no change in its refcount balance.

## Verification

Verified on Windows x64 by instrumenting `Drop` with a live counter and
spawning 400 children per mode: unfixed leaves 400 live writers after
each of the drain (64 B into `sort`) and reject (256 KB into `cmd /c
exit`) workloads; fixed returns to 0 on both, in release and debug
builds.

Also verified on Windows x64: `spawn.test.ts -t 'stdin|Uint8Array|Blob'`
(45/45), `spawnSync.test.ts` (6/6), `file-io.test.ts` (26/26),
`child_process.test.ts` (41/41), and on Linux: `bunshell.test.ts`
(414/414), `bun-security-scanner-workspaces.test.ts` (3/3).
`rust:check-all` is green across all 10 targets.

Found while working on #35286, which scopes its change to the
empty-buffer path and does not overlap.
Jarred-Sumner pushed a commit that referenced this pull request Aug 13, 2026
…ails on POSIX (#37774)

### Problem
- On POSIX, a Buffer or Blob passed as a child's `stdin` leaks the
native writer that pumps it into the child when the write fails before
the buffer drains, typically `EPIPE` because the child closed its stdin
without reading it.
- Reached by the shell's `cmd < ${buffer}` redirect on every POSIX
configuration, and by `Bun.spawn` always on macOS but on Linux only when
memfd is unavailable.
- Under LeakSanitizer the shell's stranded writers appear as `Direct
leak of 1024 byte(s) in 2 object(s)` from
`StaticPipeWriter<ShellSubprocess>::create`; with refcount logging the
count stays at 1 forever after `onError(err=EPIPE: Broken pipe
(send()))` and `onClose()`.
- Cause: the writer holds a ref on itself while a write is in flight,
and only a drained buffer or the owner closing it at exit released that
ref. After a failed write the writer closes itself and the owner empties
its slot, so nothing that could release the ref can still reach the
writer.

### Fix
- The writer's close callback releases the in-flight ref on every
platform, not only Windows. Sound because close is the last callback a
parent receives for an error, and every release site claims the same
token first, so exactly one of them (drain completion, close after a
failure, or the owner) releases.
- The POSIX drain loop now only writes and cannot invoke callbacks
itself; an error is always returned and reported once by the caller.
This deletes the arm that #35297 cited when it fixed the same leak on
Windows only; the arm was unreachable, so no behaviour changes here.
- Two rarer error paths get the same report-then-close shape: a failed
poll re-registration used to report without closing, and a zero-byte
write closed without releasing. Both are reasoned about, not tested. Out
of scope, pre-existing: on Windows a write failing synchronously inside
`start()` still strands the ref; tracked separately.
- Verification: a new ASAN-lane test runs a fixture under
`detect_leaks=1` that drives both owners through failing and draining
writes. It fails 4 of 4 runs without the fix with the report above and
passes 5 of 5 with it. LSan only reports the shell-owned writers; the
`Bun.spawn` cases exercise the same teardown without being what fails.

### Background
- The static pipe writer is the native object that writes one fixed
in-memory buffer (a Buffer or Blob `stdin`) into a child's stdin pipe.
It is refcounted: one ref lives in the owning process's stdin slot, a
second is taken when the write starts so the object outlives the write.
- It has two owners: a `Bun.spawn` subprocess and a shell subprocess for
the `< ${buffer}` redirect. On Linux `Bun.spawn` normally hands the
child a memfd and never creates the writer, which is why the test
disables memfd; the shell redirect always uses it.
- The buffered pipe writer underneath reports to its parent through
three callbacks: bytes drained, error, closed. Parents are written
assuming closed is the last one they receive, so freeing the object
there is safe only if nothing underneath touches it afterwards.
- The `started` flag is the token for the in-flight ref: whichever site
swaps it to false does the release, so three possible release sites
cannot release twice.
- `EPIPE` is what writing to a pipe returns once the reader has closed
its end; it is how a child closing its stdin reaches the parent while
the buffer is still being written.

<!-- robobun:evidence:begin -->

---

**no test proof** · iteration 0 · Platform-specific test(s) that do not
run on this machine. Deferring to CI, which covers all platforms:
test/js/bun/spawn/spawn-stdin-pipe-fd-leak.test.ts

<!-- robobun:evidence:end -->

<details>
<summary>Original description</summary>

On POSIX, a Buffer/Blob `stdin` whose write fails before it has drained
(typically EPIPE, because the child closed its stdin without reading it)
leaks the native `StaticPipeWriter` that pumps the buffer into the
child. Two owners share that writer: the shell's `cmd < ${buffer}`
redirect, which uses it on every POSIX configuration, and `Bun.spawn`,
which on Linux only uses it when memfd is unavailable
(`BUN_FEATURE_FLAG_DISABLE_MEMFD=1`, or no `memfd_create`; otherwise the
child gets a memfd) and on macOS always.

### Repro

```ts
// BUN_FEATURE_FLAG_DISABLE_MEMFD=1 BUN_DEBUG_StaticPipeWriter=1 BUN_DEBUG_ref_count=1 bun-debug run repro.ts
const big = Buffer.alloc(1 << 20, 0x61);
const proc = Bun.spawn({ cmd: ["sh", "-c", "exec 0<&-; sleep 0.3"], stdin: big, stdout: "ignore" });
console.log("exit", await proc.exited);
```

Before, for the writer:

```
StaticPipeWriter(0x..) start()
0x..   ref 1 -> 2                      start()
StaticPipeWriter(0x..) onError(err=EPIPE: Broken pipe (send()))
StaticPipeWriter(0x..) onClose()
0x.. deref 2 -> 1                      owner drops create()'s ref in on_close_io
```

and the count stays at 1 forever. After, the same trace continues with
`deref 1 -> 0`. `$\`cmd < ${big}\`` with a command that exits without
reading stdin shows the same before/after (no memfd flag involved), and
under LeakSanitizer the shell's stranded writers come out as

```
Direct leak of 1024 byte(s) in 2 object(s) allocated from:
    ...
    #12 <StaticPipeWriter<ShellSubprocess>>::create src/spawn/static_pipe_writer.rs:110
    #13 <shell::subproc::Writable>::init src/runtime/shell/subproc.rs:1149
```

### Cause

`start()` takes a ref on the writer and sets `started`; that ref was
released from `on_write` when the buffer drained, or by the owner
(`Subprocess::on_process_exit` / `close_io`) if it closed the writer
while the slot still held it. A failed write takes neither route:
`PosixBufferedWriter::_on_error` runs `on_error` and then `close()`,
`on_close` tells the owner, the owner empties its slot and drops
`create()`'s ref, and nothing is left that can find the writer to
release `start()`'s ref.

#35297 fixed exactly this on Windows by releasing in `on_close`, and
left POSIX alone because of the shape of
`PosixPipeWriter::drain_buffered_data`: it had an arm that, for an error
after a partial drain, called `on_error` inline (closing the writer) and
returned `Wrote(n)`, after which `on_poll` delivered `on_write(n,
Drained)` to the same object, so a release in `on_close` looked unsafe.
That arm was in fact unreachable (`try_write` reports a short write as
`Pending`, never as `Wrote`, so the drain loop never gets to an error
with bytes already drained), but as written it was the documented reason
the POSIX release site did not exist.

### Fix

* `drain_buffered_data` (src/io/PipeWriter.rs) loses that arm and takes
`&self`, so it structurally cannot dispatch callbacks: an error is
always returned as `Err` and reported once by the caller, and `on_close`
is the last callback a parent sees. That is the contract the parents are
written against (`FileSink::on_close` releases its keep-alive as "the
last thing", `Terminal::on_writer_close` derefs the terminal,
`FileSink::on_auto_flush` documents `flush()` returning `Err` as the
error contract); this makes it explicit rather than a property of which
arms happen to be reachable. No behaviour changes here.
* `StaticPipeWriter::on_close` (src/spawn/static_pipe_writer.rs) claims
and releases `start()`'s ref on every platform, not just Windows. This
is the behavioural fix. The release is the last access: the frames
underneath it (`close_impl` -> `close` -> `_on_error` -> `on_poll`) do
nothing with the writer after the callback, which is the same shape
`SecurityScanSubprocess` (whose owner ref is the last one) already
relies on in `on_close_io` today. `on_write` keeps taking the token
before it closes and the owners keep taking it before they close, so
exactly one site releases the ref.
* `PosixBufferedWriter::register_poll` reports a failed re-registration
through `_on_error` (report, then `close()`), like every other error
report and like the streaming writer's `register_poll` already did,
instead of reporting and leaving the writer open. Raised in review: that
(ENOMEM-class) failure was the one report not followed by the `on_close`
that now releases the ref; `Bun.spawn` would still have picked the
writer up at exit, the shell had nothing to pick it up with. Reasoned
about rather than tested, since it needs the registration syscall itself
to fail.
* The `EndOfFile` arm of `on_write` releases the ref as well (non-final,
since the owner's ref is dropped by the `on_close` the buffered writer
delivers right after) instead of closing the writer itself and leaving
the ref outstanding. That arm needs `write(2)` to return 0 on a pipe, so
it is reasoned about rather than tested; it is the same change #37755
makes to this arm.

Known gap, pre-existing and not touched here: on Windows a `uv_write`
that fails synchronously inside `start()` closes the writer (`on_close`
runs, the owner drops its ref) before `start()` sets `started`, which
strands the ref the same way. Fixing it needs `SecurityScanSubprocess`'s
post-`start()` release to become token-aware as well, so it is tracked
separately.

Related: #34697 proposes the same `drain_buffered_data` change as one
item of a broader hardening pass, but is 600+ commits behind with
conflicts in three files. #37755 moves these callbacks onto raw `this`
pointers and leaves the error chain (and this leak) alone; the two
conflict textually in `on_close` / `on_poll` but compose, whichever
lands second needs to keep the unconditional release in `on_close` and
the `Err` return in `drain_buffered_data`.

### Test

`test/js/bun/spawn/spawn-stdin-pipe-fd-leak.test.ts` runs a fixture on
the ASAN lane with `detect_leaks=1` (the setup from
shell-worker-terminate-leak.test.ts). The fixture drives both owners
through both endings: children that close their stdin, report it and
wait to be killed (so the write fails while the child is alive and the
exit path cannot be what cleans up), and children that drain it; memfd
is disabled so that the `Bun.spawn` scenarios reach the writer at all.
Unfixed it fails every time (4 of 4) with the report quoted above: the
two shell-owned writers. The two stranded `Bun.spawn`-owned writers from
the same run have their refcount stuck at 1 just the same (checked with
`BUN_DEBUG_ref_count`, and their `Subprocess` structs are freed before
exit), but LSan still finds their address somewhere and does not report
them, so those scenarios only exercise the same teardown under ASAN.
Fixed, the fixture is clean, 5 of 5 runs, about 0.7s each.

An earlier revision used a live-writer counter in
`bun:internal-for-testing`; it was removed per review in favour of LSan.

### Verification

Debug (ASAN) build: the file above, plus spawn.test.ts,
spawnSync.test.ts, spawn-empty-arrayBufferOrBlob, spawn-streaming-stdin,
spawn-stdin-readable-stream, spawn-stdin-destroy,
spawn-pipe-start-error, spawn-many-teardown, memfd-disabled,
bunshell.test.ts (418 pass), bunshell-instance, epipe,
shell-blocking-pipe, shell-write-fault, file-io, pipeline_stack,
filesink.test.ts, terminal.test.ts, terminal-spawn,
child_process.test.ts and bun-security-scanner-workspaces all pass.
`cargo check` of bun_io and bun_spawn for `x86_64-pc-windows-msvc` and
`aarch64-apple-darwin`, `cargo clippy` on both, and `cargo fmt --check`
are clean. CI on the two previous revisions (the first of which ran its
tests on every lane, Windows included) was green apart from flaky tests
that passed on retry.

</details>
… close() returns

`_on_error` in `PosixStreamingWriter` and `PosixBufferedWriter` reports the
error to the parent and then closes the writer. The writer is a field of the
parent, and `on_error` can release every other ref on the parent: `FileSink`
rejects a promise in it, and for a stream piped in by `Bun.write` the rejection
handlers close the sink and release the pump's ref. The `close()` that follows
then ran on freed memory (ASAN: heap-use-after-free in
`PosixStreamingWriter::close`).

Both writers now take a ref on the parent before `on_error` and release it
after `close()`, through a new `PosixWriterParent` trait (`ref_`/`deref`) that
the parent macros stamp from the expressions they already receive for Windows.
The failed-registration arm of `PosixStreamingWriter::register_poll` has the
same order and takes the same ref.
@robobun robobun changed the title io: harden POSIX pipe writer error paths against owner-dropping callbacks io: POSIX pipe writers hold a ref on their parent from on_error until close() returns Sep 30, 2026
@robobun
robobun force-pushed the farm/52c8d90b/shell-iowriter-error-path-hardening branch from f0036f3 to f29b67c Compare September 30, 2026 22:56
Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/io/PipeWriter.rs Resolved
Comment thread src/io/PipeWriter.rs Resolved
@robobun

robobun commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (5a183c1) and force-pushed as f29b67c. The PR is now one change and one test: both POSIX pipe writers hold a ref on their parent from on_error until close() returns.

Why now. On an ASAN build, the script below reads the stdout sink after it is freed. The read is in PosixStreamingWriter::close, called from _on_error. The free is inside the Parent::on_error call one line above it.

cat > sink.mjs <<'JS'
await Bun.write(Bun.stdout, new Response(new ReadableStream({ type: "direct",
  async pull(c) { c.write(new Uint8Array(1 << 20)); await c.flush(); c.close(); } })));
JS
bun sink.mjs | (sleep 0.1; head -c 262144 > /dev/null)

How I reproduced it. Debug ASAN build of main at 11c41c6, Linux x64: 3 of 3 runs report heap-use-after-free. With this branch the same runs exit with one EPIPE: broken pipe, write. The new test in test/js/bun/util/filesink.test.ts fails on the ASAN build of main with that report and passes here.

What left the PR. Main already has the FIFO redirect change (#34696) and the StaticPipeWriter changes (#37774), and the macOS libinfo code is gone. The Notes in the PR body list the rest.

The guard is now a named Drop type (ParentKeepAlive), for the review comment about an RAII wrapper.

@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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline nit on the test's EAGAIN loop, I also checked the new PosixWriterParent stamping for conflicts: the #[cfg(unix)] / #[cfg(not(windows))] gates match the sibling Posix*WriterParent impls each macro already emits, no parent invokes both macros (so no duplicate impl), and Terminal's hand-written impl carries the same #[cfg(unix)] gate as its existing PosixStreamingWriterParent impl. I also looked at the three PosixBufferedWriter/PosixStreamingWriter _on_error and register_poll sites for a path where the guard is dropped before close() returns — each binds _keep_alive in the enclosing scope so it outlives the trailing close().

Extended reasoning...

This rebase adds a PosixWriterParent supertrait and an RAII ParentKeepAlive guard to the POSIX pipe writers in src/io/PipeWriter.rs, stamps the impl via the two parent macros and a hand-written Terminal impl, and adds a FIFO-based FileSink regression test; it touches no auth, crypto, or input-parsing surface. It is unsafe refcount/lifetime code with an outstanding CHANGES_REQUESTED review from a maintainer predating this push, and one verified test-robustness nit is posted inline, so this is not an approve.

Comment thread test/js/bun/util/filesink.test.ts Resolved
No code change: the docs of PosixWriterParent and ParentKeepAlive are one line each, the section banner is gone, and the module comment above the parent macros is back to the text on main.

@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.

Code review found no issues

No high-confidence issues detected in this change.

Still open from earlier reviews (1):

  • Unresolved: 1 minor or pre-existing.

@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.

Code review found no issues

No high-confidence issues detected in this change.

…line

register_poll runs on every buffered write. With the parent ref in its error arm it was no longer inlined into write(). The arm is now a #[cold] function, so the hot path is as small as before.
…oes away

The reader closed in the same step as its last read. That only finds the bug when the close lands before the child's next write: on a fast build the child often writes first, and the flush at the end of that turn reports the error instead. The reader now takes its bytes through drain(), waits a moment, and then closes.

@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.

Code review found no issues

No high-confidence issues detected in this change.

The SAFETY note in StaticPipeWriter::on_close said that its deref frees the writer on POSIX. After a failed write the buffered writer's _on_error now holds a ref until close() returns, so that deref is not the last one. FileSink::on_error no longer claims that the keep-alive ref alone keeps the sink alive until close(). No code change.

@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.

Code review completed

Nothing new to post: everything this review found is already covered by existing comments on this pull request or didn't merit a separate one.

@robobun

robobun commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI on 6861b25 (build #122410) has one failed job. What I checked for each failure:

  • test/js/bun/spawn/spawn.test.ts, an idle reader stopped at the highwater mark does not keep the process alive, x64-asan: fails on every retry. It tests the stdout pipe reader, and the child writes with fs.writeSync, so the pipe writers of this PR are not in it. The same failure is on main and on unrelated PR builds.
  • test/js/bun/console/console-write.test.ts, an awaited console.write rejects with EPIPE when the reader has hung up (several arguments): failed in the parallel batch on four lanes and passed alone. The output is caught EPIPE and then an unhandled EPIPE. console.write: restore the implementation from before #43649 #44351 describes this failure as flaky on main. It restored the old console.write there and made this test a todo. This branch is based on 5a183c1, which is before console.write: restore the implementation from before #43649 #44351, so its CI still runs the test. A rebase onto current main removes it.
  • The other entries passed on retry: four on Windows lanes, fetch-leak.test.ts and serve-body-leak.test.ts (memory thresholds), node-tls-server.test.ts (49 of 50 connections counted), build-toolchain-identity.test.ts, and structuredClone-classes.test.ts (a test worker crash on alpine x64 that is also in builds of unrelated branches).

This diff does not take part in the console.write failure. console.write keeps its sink in a slot of the console object, so the ref that this PR takes in _on_error is never the last one there, and the PR changes nothing else on that path. The entry is on 2 to 4 lanes in each of the last four builds of this PR. For comparison, 21 finished builds of unrelated branches from before #44351 (#122030 to #122059) have it on 0 to 2 lanes each, 16 of them on at least one, and #122064 has it on 5.

test/js/bun/util/filesink.test.ts, which has the test of this PR, has no failure entry in this build.

Jarred-Sumner added a commit that referenced this pull request Oct 13, 2026
…wind plugin, native JavaScript plugins, a faster `Bun.Glob` (#45043)

### What does this PR do?

Follow-up to #44805. That PR made `bun lint` and `bun format` (now `bun
fmt`) match ESLint, oxlint, Prettier and oxfmt for people who migrate.
This one is for someone who has none of those and types `bun lint` for
the first time.

With an ESLint, oxlint, Prettier or oxfmt config, what changes moves
toward the tool itself: findings come in oxlint's order, files that
oxlint accepts are no longer refused, and a Prettier config that names
`prettier-plugin-tailwindcss` is formatted and not refused. The
exceptions are a few outputs of Prettier and oxfmt that change what a
file means, which Bun no longer copies. Each is listed below.

It also moves the host for JavaScript plugins (third-party ESLint rules)
from JavaScript to native code, and runs it on the thread that lints the
file. See "JavaScript plugins" below.

It fixes bugs that #44805 put on `main`, two of which rewrite files they
shouldn't. See "Bugs in #44805".

#### `bun format` is now `bun fmt`

The formatter's subcommand is `bun fmt`, like `cargo fmt`, `go fmt`,
`deno fmt` and `zig fmt`. Its section in `bunfig.toml` is `[fmt]`
(`[fmt.sortImports]`, `[[fmt.overrides]]`). Neither name has been in a
release.

- Most projects already have a `"format"` script. A script with the
command's name wins over the command, so `bun format` ran Prettier until
the script was changed. `bun fmt` is the formatter from the first run.
- `bun format` is no longer a command. It runs the project's `format`
script, as it did before. Without one it says `Script not found
"format"` and `note: The formatter is bun fmt`.
- A `[format]` section in `bunfig.toml` is refused (`Unknown section
[format]`, `Did you mean [fmt]?`), not ignored.
- What wins over the command is now called `fmt`: a `fmt` script (with
`prefmt` and `postfmt`), `fmt.ts`, `fmt/index.js`,
`node_modules/.bin/fmt`. Inside a `fmt` script, `bun fmt` is the
formatter.
- Unchanged: the `--format` flag of `bun lint` and `bun fmt`, `format =
".."` under `[lint]`, the rule `bun/format`, and the docs URLs.

#### Prettier plugins that are built in

`bun fmt` doesn't load Prettier plugins, and it refused every file of a
project whose `.prettierrc` named one it didn't know. That included
`prettier-plugin-tailwindcss`, the most used plugin there is (10 M
downloads a week), although Bun has had a native port of it since
#44805. It could only be turned on from `bunfig.toml`.

- [x] **`prettier-plugin-tailwindcss` in a Prettier config now just
works.** Leave it in `plugins`.
- However it's named: the bare name, a path or `file:` URL into
`node_modules`, a `URL`, the imported module object, in `overrides`,
with `--plugin`, in `package.json`, in a shared config. `plugins: []` in
an override turns it off.
- All eight options (`tailwindConfig`, `tailwindStylesheet`,
`tailwindEntryPoint`, `tailwindFunctions`, `tailwindAttributes`,
`tailwindPreserveWhitespace`, `tailwindPreserveDuplicates`,
`tailwindPackageName`), with the plugin's defaults, its rule for
relative paths, and its error for a value of the wrong type.
- The plugin's own rules for JavaScript (nested calls, member chains,
`/regex/` names), which differ from oxfmt's.
- When `tailwindcss` isn't installed, or is version 4 with a JavaScript
`tailwindConfig`, or version 3 with a style sheet, the real plugin uses
a Tailwind it bundles. Bun then asks the installed plugin's documented
`sorter` entry for the order of the classes. Nothing is ever downloaded.
  - MDX, `<DIV CLASS="…">` and LWC files are sorted too.
- [x] Another plugin next to it is still refused, and only that one is
named.
- [x] "All matched files use Prettier code style!" is no longer printed
above "1 file was not formatted".
- [x] **`@prettier/plugin-oxc`** is accepted. It only swaps the parser:
real Prettier prints 3,939 files byte for byte the same with and without
it. Its order relative to the Tailwind plugin in `plugins` matters in
Prettier, and does here.
- [x] **`prettier-plugin-packagejson`**: files named `package.json` go
to the installed Prettier, like `.svelte` files with the Svelte plugin,
and everything else is formatted natively. Before, every file of the
project was refused. Bun's `sortPackageJson` isn't used for it, because
it's oxfmt's order and not the plugin's: 28 of 50 made-up files come out
different.
- [x] The warning names the plugins that have no effect, not `plugins`
as a whole.

| plugin in `.prettierrc` | downloads a week | what happens |
|---|---:|---|
| `prettier-plugin-tailwindcss` | 9.95 M | built in (new) |
| `@trivago/prettier-plugin-sort-imports`, `@ianvs/…`,
`prettier-plugin-organize-imports` | 5.9 M | built in |
| `@prettier/plugin-oxc` | 0.28 M | built in (new) |
| `prettier-plugin-packagejson` | 1.23 M | its files go to the installed
Prettier (new) |
| `prettier-plugin-svelte`, `-astro`, `@prettier/plugin-xml`, `-sh`,
`-sql`, `-toml`, `-java`, … | 5.5 M | their files go to the installed
Prettier |
| any other (`-jsdoc`, `-sort-json`, `-css-order`, …) | | the files it
applies to are refused, and it's named |

`prettier-plugin-jsdoc` stays refused on purpose. Bun's `jsdoc` option
follows oxfmt's, which is a rewrite of the plugin: on 251 real files
with 3,222 JSDoc comments, 26 files differ from the plugin's output.

Compared with Prettier 3.9.9, the plugin 0.8.1, and Tailwind 4.3.3 and
3.4.19: 13,654 of 13,952 JavaScript and TypeScript files are byte-equal
(57 contexts, 32 expressions, 4 sets of options), 2,148 of 2,176 files
in HTML, Vue, Angular, LWC, Handlebars, CSS, SCSS, Less, Markdown and
MDX, and all 15 Tailwind 3 projects (custom themes, `prefix`,
`important`, `separator`, `@apply`). About half of the differences are
the one below. The rest: a directive inside a function inside `cn(…)` in
TypeScript, and Vue or Angular bindings that don't parse.

One deliberate difference. The real plugin trims a class string that
touches other text, which joins two classes: `` className={`header${open
? " active" : ""}`} `` becomes `` `header${open ? "active" : ""}` ``, so
the element gets `headeractive`. It happens in `.ts`, `.tsx`, `.jsx` and
Vue. Bun keeps that blank.

#### Formatting that changed what a file means

#44805 re-parsed every file after formatting it and compared the trees.
That cost up to 21% of a run, and on 10,100 real files it refused none.
**It's off by default now, and `--debug-check` turns it on**, like
Prettier's flag of that name.

The only inputs it ever caught were ones where Prettier's or oxfmt's own
output means something else and Bun printed the same bytes. So the
printers are fixed instead. Each row is in `test/cli/format`, with the
tool's output next to Bun's:

| input | Prettier 3.9.9 / oxfmt 0.72 | now |
|---|---|---|
| `font-family: Font\ Awesome` | `Font\Awesome` (`\A` is a hex escape) |
kept |
| `b: d\ ;`, `@extend .a\ ;`, `f(a\ , b)` | the backslash escapes the
next character | kept |
| `x \|b` in a selector | `x\|b`: a descendant becomes a namespace |
kept |
| `a ? b : c;` then `(d ? e : f) ? g : h;` with `--no-semi
--experimental-ternaries` | no `;` before the `(`: one call | `;(` |
| `a < b > c` in TypeScript, broken after the `>` | reads as `a<b>; c` |
doesn't break there |
| `<!DOCTYPE html>`, `<textarea>`, `<pre>`, a `<script>` with `// a` in
Handlebars | dropped or joined | kept |
| `{{a.[]}}`, `{{[a/b]}}`, `{{~! b ~}}` in Handlebars | another path,
another comment | kept |
| a comment inside a TOML inline table | the rest of the table is
commented out | one entry per line |
| YAML `>+` with `--prose-wrap=never`, `? \|+` as a key, `--- ---`, a
key over two lines in a flow map | the value changes, or the output
doesn't parse | the same value |
| `{{concat "p-4 flex " x}}` with Tailwind sorting | the class joins the
value of `x` | kept |
| a file that is nothing but no-break spaces | emptied | kept |

- It costs no parity on real code: both upstream suites pass with their
expected files untouched. On 14,835 small style sheets 51 differ from
Prettier, and all 51 have a backslash right before white space.
- `--debug-check` for Handlebars compares the two parsed trees (it only
read the printer's own flag), and with Tailwind sorting on it compares
the text that would be written.
- `bun fmt` no longer builds the data for the check for every JavaScript
and TypeScript file when the flag isn't given.
- Known and left: 13 Markdown inputs with emphasis nested three deep,
and 67 upstream YAML inputs of one kind (blank lines at the end of a
block scalar that are indented deeper than it), where the upstream
snapshots record the loss.

#### What was wrong

Found by using the merged build on a fresh project, and from the first
bug reports:

- With only `bunfig.toml`, 572 of the built-in rules could not be turned
on (`Could not find plugin "unicorn" in configuration.`). Any
`@typescript-eslint/*` rule set to `warn` or `error` killed the whole
run if the project had a single `.js` file.
- A typo in `[lint.rules]` or `--rule` was ignored silently.
- `bun lint --init` wrote an `.oxlintrc.json` with a `$schema` pointing
into `node_modules/oxlint`, didn't say which file it wrote, and switched
the project to oxlint's rules and output.
- A `.tsx` file with a conditional hook, a list without `key` and a
stale effect dependency got no report, even though the rules are built
in.
- Nearly everything was an error, including `prefer-const`,
`no-explicit-any` in a `.d.ts`, and dead stores. `no-useless-assignment`
was reported as a bug because its message doesn't say why.
- Default output was ESLint's `stylish`: absolute paths, no code.
- Import sorting and Tailwind class sorting could not be turned on from
`bunfig.toml`.
- `--help` was 84 lines. Messages and docs were hard to read.
- No `--staged`, nothing to tell someone migrating what runs natively.
- A fresh `bun init` project failed `bun lint` and `bun fmt --check`.

#### With no config file

- [x] Every built-in rule can be named in `[lint.rules]`, `--rule` and
comments, under either spelling (`@typescript-eslint/x` or
`typescript/x`). No plugins to list
- [x] Rules ported from oxlint take their options
- [x] `[lint.settings]`
- [x] `[[lint.overrides]]`
- [x] An unknown rule is an error with a suggestion
- [x] A mistake in `[lint.rules]` gets a code frame of `bunfig.toml` and
a plain message
- [x] React: `rules-of-hooks`, `jsx-key` and `exhaustive-deps` are on if
`react` is in `package.json`
- [x] Likely bugs are errors. Unused or dead code and suggestions are
warnings
- [x] `.d.ts` files only get the rules that are errors
- [x] `pretty` is the default output, with a summary line
- [x] 49 hints under reports whose message alone is puzzling: `It is
overwritten on line 5 and line 12 before it is read.`, `The return on
line 4 can end the render before it is called.`, `Did you mean ===?`
- [x] `bun fmt --check` uses Bun's wording, not Prettier's
- [x] `[fmt]`: `sortImports`, `sortTailwindcss`, `sortPackageJson`,
`jsdoc`, `[[fmt.overrides]]`
- [x] `sortImports` also sorts names in `{ }` and merges duplicate
imports
- [x] TOML is formatted by default. A multi-line inline table keeps one
entry per line, `["warn", {` .. `}]` stays hugged, and a one-line table
never gets a line break (TOML 1.0 parsers reject those)
- [x] `bun fmt` skips `*.min.js`, `*.min.css` and lock files. A file
named on the command line is still formatted
- [x] `_unused` names are ignored by `no-unused-vars`
- [x] A core rule and its typescript-eslint version act as one rule (26
pairs). Setting either name sets both, and a problem is never reported
twice
- [x] A type-aware rule runs as soon as you turn it on in
`[lint.rules]`. `typeAware = true` adds the recommended set
- [x] `--deny-warnings`, `--silent` and `-A/-W/-D` work on Bun's
defaults. They used to switch the run to oxlint's rules, so
`--deny-warnings` made a failing lint pass
- [x] The hooks rules also cover files without JSX (`useThing.ts`)
- [x] A disable comment for a rule that is off is left alone

#### Default rules

Every rule that's on by default was tried on ordinary code: seven
made-up projects (an API server, a React app, a CLI, a library, a
monorepo, a folder of generated and vendored files, a collection of
idioms) and the four `bun init` templates. What got reported on code
that works was turned down, narrowed or fixed. For each change, the bug
the rule exists for was tried too and is still reported. All of this
only applies with no ESLint or oxlint config.

| Rule | Before | After | Why |
|---|---|---|---|
| `@typescript-eslint/no-require-imports` | error | off | Bun runs
`require()` and `import` in one file. `tailwind.config.ts` and React
Native's `<Image source={require(..)}>` have no alternative |
| `@typescript-eslint/ban-ts-comment` | error | warn | `// @ts-ignore`
is written on purpose |
| `no-cond-assign` | error | warn | `while (m = re.exec(s))` |
| `no-prototype-builtins` | error | warn | `obj.hasOwnProperty(k)` works
|
| `no-ex-assign` | error | warn | `err = err instanceof Error ? err :
new Error(String(err))` |
| `no-control-regex` | error | warn | ANSI escape patterns |
| `@typescript-eslint/no-wrapper-object-types`,
`no-unsafe-function-type` | error | warn | `target: Object`, `cb:
Function` |
| `@typescript-eslint/no-unsafe-declaration-merging` | error | warn |
`interface Bus` + `class Bus extends EventEmitter` |
| `@typescript-eslint/no-non-null-asserted-optional-chain` | error |
warn | `map.get("a")?.v!` |
| `@typescript-eslint/no-duplicate-enum-values` | error | warn | `enum
Level { Off = 0, None = 0 }` |
| `bun:test/no-export` | error | warn | `export const fixture` in a test
file |
| `no-unsafe-assignment`, `-call`, `-member-access`, `-return`,
`-argument` (`--type-aware`) | error | warn | About 25 of 30 errors in
an ordinary API project |
| `no-loss-of-precision` | error on everything | error on integers | A
64-bit id is a bug, `3.14159265358979323846` isn't |
| `no-irregular-whitespace` | error everywhere | error in code | French
and Japanese text in strings, comments and JSX |
| `no-unused-expressions` | warn on `cb && cb()` | quiet | It does
something |
| `@typescript-eslint/no-misused-promises` | error on `<form
onSubmit={asyncFn}>` | quiet | How React code handles events |
| `@typescript-eslint/no-namespace` | warn inside `declare global` |
quiet | There's no other way to write it |
| `no-empty-pattern` | warn on `async ({}, use) =>` | quiet | Playwright
requires the `{}` |
| `no-fallthrough` | error after `process.exit()` | `process.exit()` and
`process.abort()` end a case. With types, so does a call that returns
`never` | CLI code. `fall-through`, `fallthrough` and `no break`
comments count too |
| `react-hooks/rules-of-hooks` | error on Playwright's `use` and
Storybook's `render` | quiet | `use` is a parameter there, and Storybook
renders `render` as a component |
| `react/jsx-key` | error on every array of elements | only where React
renders the array | `steps[step]`, icon tables, `actions={[..]}` |
| `no-constant-binary-expression` | error on `{false && <X />}` | quiet
for `true`, `false`, `0`, `1` | Switching a block off |
| `no-undef` | error on a name tested with `typeof` | quiet | The author
knows it may be missing |
| `no-unused-vars` | `React` and `h` reported in files with JSX |
counted as used | Removing the import breaks the classic runtime |
| `/* eslint-env */` | fatal error | honored | Old JavaScript files are
full of them |

- [x] Three options only Bun has, so the old behavior is one line away:
`react/jsx-key` `checkArraysOutsideJSX`, `no-constant-binary-expression`
`allowLiteralToggle`, `no-loss-of-precision` `ignoreDecimals`. Under an
ESLint config they're rejected with ESLint's own error
- [x] Bun's default options stay when you only set a severity:
`"no-unused-expressions" = "error"` keeps `allowShortCircuit`. `--rules
-f json` and the docs show them as the defaults
- [x] Every global of Bun is known, and the globals of service workers
- [x] `describe`, `it`, `expect`, `jest`, `vi`, `cy` and friends are
known in `*.test.*`, `*.spec.*`, `*.e2e.*`, `*.cy.*`, in set-up files
like `jest.setup.ts` and `setupTests.ts`, and in the project's
`__tests__`, `__mocks__`, `test`, `tests`, `spec`, `e2e` and `cypress`
folders
- [x] An untouched `bun init --react` has 0 problems under `bun lint
--type-aware`. It had 5 errors

On the five code projects, every error that's left is a bug that was
planted there. On the folder of generated and vendored files, 309 errors
became 9.

#### `--fix-suggestions`

The flag applies every suggestion with nobody looking, so with no config
it now only applies the ones that can't change code that works. The rest
need `--fix-dangerously`. `-f json` still lists them all, and nothing
changes under an ESLint or oxlint config.

| Rule | What its suggestion did to working code |
|---|---|
| `no-unused-vars` | Deleted `const sent = sendEmail(user);`. Dropped
the unused `next` of an Express error handler, which Express recognizes
by `fn.length === 4` |
| `no-unused-private-class-members` | Deleted `#x = sideEffect();` |
| `no-explicit-any` | `any` became `unknown`: type errors |
| `react-hooks/exhaustive-deps` | `[ms]` became `[cb, ms]`: the effect
runs at other times |
| `require-await` | Dropped `async`: callers get `T`, not `Promise<T>` |
| `await-thenable` | `await null;` became `null;` |
| `no-array-delete` | `delete list[0]` became `list.splice(0, 1)`, which
shifts every later item |
| `ban-ts-comment` | `@ts-ignore` became `@ts-expect-error`: a type
error wherever the next line is fine |
| `no-empty-object-type` | `interface Empty {}` became `type Empty =
object` |
| `no-non-null-asserted-optional-chain` | Dropped the `!` |
| `no-case-declarations` | Wrapped the case in `{ }`: a later case that
uses the `let` breaks |
| `no-floating-promises` | Wrote `void save();`: "Fixed 1 problem" with
nothing fixed |

The first two aren't offered at all when they'd delete code that runs.
Unused imports still go, with their statement if nothing else is
imported, as in ESLint and oxlint. A declaration or a disable comment
that's removed takes its line with it, so `bun fmt --check` passes
afterwards.

#### Bugs in #44805

These are on `main` today.

- [x] **`echo "# hi" | bun fmt --parser markdown` ignored stdin and
rewrote every file in the directory as markdown.** Without paths,
`--parser` now formats stdin like Prettier and never touches a file.
With real Prettier 3.9.9 as the judge: 252 of 288 parser cases, 108 of
114 flag and config cases and 26 of 31 plugin cases are the same in
stdout, stderr, exit code and touched files. None of the rest is about
stdin (positions of some syntax errors, `oxc` parsers that Bun has built
in). On `main`, 280 of the 288 differ
- [x] `--parser x` with a directory is refused with no config or an
oxfmt config, with a glob to use instead. Under a Prettier config it
reads every file with that parser, like Prettier (the same 39 of 45
files in a mixed project)
- [x] **`bun --help format` and `bun -h format` formatted the
directory.** They print help
- [x] **`bun --check format a.js` rewrote the file and exited 0.** Flags
of `lint` and `format` that stand before the command were dropped. They
count now, as for `bun --bail test`
- [x] **`bun fmt` no longer re-parses what it has formatted.** #44805
compared the syntax tree of every formatted file with the original and
refused to write on a difference. On 10,100 real files that change it
refused none, the only refusals were inputs where Prettier itself loses
something, and it cost up to 21% of a run. It is `--debug-check` now, as
in Prettier. `--verify`, `--no-verify` and the `verify` key in
`bunfig.toml` are gone
- [x] A plugin that throws something odd (`Object.create(null)`, an
object with a throwing `message` getter, after `node.loc = null`)
aborted the process. 345 combinations of where and what: no abort, and
the exit code is the real tool's except where Bun doesn't run a custom
parser
- [x] An `eslint.config.mjs` with a top-level `await` that never settles
made `bun lint` spin forever. It's an error now
- [x] A rule with both `create` and `createOnce` ran through
`createOnce` under an ESLint config. ESLint calls `create`
- [x] Under an oxlint config, `--type-aware --type-check` reported no
type errors once an `import/*` rule was on (70 errors in real oxlint, 0
in Bun, exit 0). 22 of 28 scenarios differed from oxlint 1.87, now 0
- [x] Under an oxlint config: `-A`, `-W` and `-D` didn't override rules
from `extends`, `--fix-suggestions` dropped the safe fixes of JS
plugins, `globals: { x: "off" }` hid a global of the `env`,
`no-implied-eval` had the wrong severity, `NaN == NaN` was reported
once, and invalid values for `settings.react.version` and
`no-unused-vars` were accepted. All now equal oxlint 1.87
- [x] Under an oxlint config, plugins see oxlint's `sourceType`,
`parserOptions.ecmaFeatures` and strict mode per file. With 199 rules on
31,379 files, Bun reports 95.13% of what oxlint 1.87 reports, up from
90.44%, and what only Bun reports went from 1,107 to 173. No rule got
worse in either direction. What's left is nearly all one thing: a script
has no module scope in oxlint
- [x] `bun fmt --doctor` said "You can remove: prettier" while files
were skipped because of a Prettier plugin
- [x] **A folder named `package.json`, `.prettierrc` or
`prettier.config.js` anywhere in a project made `bun fmt` give up on the
whole run** ("Cannot read the configuration file ...: EISDIR", exit 2).
Prettier skips such folders, and so did `bun lint`
- [x] `bun -c format` and `bun -l format` rewrote files and exited 0:
short flags before the command were dropped. `bun -c=other.toml lint` is
still Bun's own `--config`
- [x] `bun --config=other.toml lint`: a mistake in `[lint.rules]` was
shown with a code frame from `bunfig.toml`
- [x] `--staged` and `--changed` dropped files that were named through a
symlinked path
- [x] `bun lint --fix` and `bun fmt` could write a file twice when two
paths lead to it (a link, or another letter case on Windows). A run
writes each real file once
- [x] Under an oxlint config, the error for a JavaScript rule that
throws vanished when a rule about several files (`import/no-cycle`) was
on too: Bun printed the cycle warnings and exited 0, where oxlint exits
1
- [x] In a `.cjs` file under an oxlint config, a plugin that called
`markVariableAsUsed("first")` silenced `no-unused-vars` for the next
variable instead
- [x] A `package.json`, `tsconfig.json` or rule option nested tens of
thousands of levels deep overflowed the stack

#### Like oxlint, under an `.oxlintrc.json`

Compared with oxlint 1.87:

| | Before | After |
|---|---:|---:|
| 127,614 small files: same verdict, and every error identical in words,
labels and help | 82,600 of the first 88,086 | **all 127,614** |
| Files Bun refuses and oxlint accepts | 112 | 0 |
| Files Bun accepts and oxlint refuses | 92 | 0 |
| 4,703 rows of syntax errors in `lint.test.ts` | | 0 differ; 17 more
are listed as known, and both tools refuse all 17 |
| oxlint's own test cases with several messages, in its exact order |
634 of 713 | **713 of 713** |
| 7,828 findings in real files, in oxlint's relative order | 88.9% | all
but 1 |
| …and at exactly oxlint's place | 37.1% | all but 4 |

- [x] **Findings are printed in the order in which oxlint runs its
rules**, not by position: node by node as oxc visits them, then rule by
rule. It costs nothing: with every category on, 62,000 findings in 220
files take 0.1% fewer instructions than on `main`, which printed them in
another order.
- [x] **A file has two scope analyses, as in oxlint.** oxlint's own
rules see oxc's scopes. JavaScript plugins, and native rules that oxlint
doesn't have, see typescript-eslint's. One shared analysis gave false
positives in oxlint's own rules as soon as any plugin was on (13 of 87
files). The second one is built on first use: a plugin that never asks
about scopes pays nothing, one that walks every scope pays 2.2%.
- [x] `Scope::references` is in the order in which typescript-eslint's
scope manager makes them (compared on 20,000 random programs). That
fixed two of Bun's own rules,
`no-unnecessary-parameter-property-assignment` and
`react/hook-use-state`, which differed from ESLint in 16 of 27 and 16 of
23 files.
- [x] `Variable`, a view that is ESLint's `Variable` one for one, for
ported rules. Eleven rules use it, and three private copies are gone.
- [x] When a rule throws, the file keeps the findings of oxlint's own
rules and loses those of every plugin rule, as in oxlint (21 cases). A
native rule that oxlint lacks counts as a plugin rule.
- [x] oxc reads a file that can be a script or a module as a script
first. If it turns out a module, oxc goes back to each statement where
`await` was a name, and forgets every parser error since. About 50 kinds
of error are accepted by oxlint that way, and now by Bun.
- [x] `--fix`: of two fixes with the same range, the rule that oxlint
runs first wins, and what is left is printed in oxlint's order.
- [x] `markVariableAsUsed` from a plugin doesn't silence oxlint's own
`no-unused-vars`. It doesn't in oxlint either. Two tests that said
otherwise had been recorded from Bun.
- [x] A key written twice in a rule's options, `settings`, `globals` or
`env` is there once, at its first place, with its last value. A YAML
`.eslintrc` with one is refused, as in ESLint 8.57.1.
- [x] A file that oxc's parser or its scope pass refuses is refused,
with every error of the file, in oxlint's order, with its `TS(nnnn)`
code, labels and help: redeclarations, duplicate and undefined exports,
reserved words, assignment targets, TypeScript's grammar errors, `await`
and `yield` where they can't be, private names outside a class
- [x] 89 of 109 common syntax errors (`f(a b)`, `x = ;`, `if (a {}`)
have oxlint's exact words, up from 4
- [x] A file's findings are printed in oxlint's three groups: built-in
rules by place, JavaScript plugins' in the order reported, then every
unused disable directive
- [x] Unused bare `eslint-disable` comments under the default config:
821 differing files, now 0. With the `jsdoc` or `vue` plugin on: 334,
now 0
- [x] Config files: the last of two duplicate keys wins (22 of 22 cases,
was 7), `#` comments and a `#!` line are accepted, options for a rule
that takes none are refused
- [x] JavaScript plugins see `Program` start at the first token, and the
scopes of oxc's source type: a script has only `global`, CommonJS has
`global` and a function scope with `arguments`
- [x] `cx.throw(node, "Error", message)` lets a native rule fail the way
a JavaScript rule does when it throws
- [x] None of it costs a file without such an error more than a few bit
tests: `bun lint` under `{}` on 9,384 real files runs 4,004 M
instructions, against 4,006 M before

Deliberately not copied from oxlint:

| | oxlint 1.87 | Bun |
|---|---|---|
| `--fix` with 33 or more messages | an unstable sort shuffles the
findings that have no fix (lines 21, 3, 4, …, 20, 2) | run order |
| `await; await (x); export {};` and the like | accepted; the rules run
on a tree with dummy nodes (`'' is not defined` at 1:1), and it panics
with a JavaScript plugin | accepted; `await` is a name there |
| `declare function ();` | `func-names` reports it | silent; `tsc`
rejects the code |
| two call-signature literals in a union,
`typescript/prefer-function-type` | reports each twice | once |
| several ungrouped accessor pairs in one class,
`grouped-accessor-pairs` | in the order of a hash table | by place |
| 17 shapes that both tools refuse | | other words, or one line fewer |

Known and not yet matched: **when an `overrides` entry matches a file,
oxlint runs its rules in another order.** It rebuilds the rule list
through an `FxHashMap` and collects it without a sort
(`Config::apply_overrides`), so the rules run in the table's order,
which also differs between x64 and arm64. Bun keeps rule-number order
there. Only the order of a file's findings differs, never which are
reported. On 60 open-source projects with every category on, 15,951
files have findings: 8,256 are in oxlint's exact order (7,870 before
this PR's last rounds), and 1,542 of the 1,941 that have the same lines
in another order are in projects with `overrides`.

Copied although it's worse for users, as on `main`:
`import/no-duplicates` reports a duplicate only if the two specifiers
are neighbors in oxlint's hash table. In a file with 56 duplicates it
reports one. And `jest/no-identical-title` imitates an unstable sort
above 20 calls with one title.

#### The same output on every CPU

An arm64 CI lane found that one rule reported a finding on x64 and
nothing on arm64. Rust's `hashbrown` looks at 16 slots at a time with
SSE2 and 8 with NEON, so a table's iteration order differs between the
two once it's crowded.

- [x] Bun's emulation of oxc's tables had been made to follow the CPU it
was compiled for. It's a constant again.
- [x] Eight places iterated a real hash table on a path to the output.
The worst: when `.oxlintrc.json` has `extends`, **which setting of a
rule wins** followed the table. Also the names in `exhaustive-deps`'
message, and the order of findings of four rules. All go through the one
emulation or a sort now. It was compared with the real table on 60,000
random sequences: 0 differ, and with a width of 8 as a control 18,400
do.
- [x] `#![deny(clippy::iter_over_hash_type)]` in the ten lint crates.

#### Faster

CI's LTO builds, `main` at the merge base against this branch, user
instructions, 13,600 real files:

| | `main` | this branch | |
|---|---:|---:|---:|
| `bun lint`, oxlint config, every category on, `-f unix` | 698 M | 697
M | -0.14% |
| the same, default format | 705 M | 701 M | -0.61% |
| `bun lint`, `.oxlintrc.json` with `{}` | 3,955 M | 3,868 M | -2.21% |
| `bun lint`, ESLint config with 5 rules | 1,596 M | 1,576 M | -1.19% |
| `bun lint`, no config | 5,109 M | 5,026 M | -1.62% |
| …in `test/js/node/test/parallel` | 773 M | 764 M | -1.20% |
| …in `test/bundler` | 469 M | 456 M | -2.76% |
| …in `src/js` | 315 M | 314 M | -0.33% |
| …in `test/js/bun` | 1,058 M | 1,047 M | -1.11% |
| …in `test/cli` | 961 M | 934 M | -2.84% |
| `bun check`, 220 files | 3,949 M | 3,933 M | -0.43% |
| `bun fmt --check`, 4 folders | 3,837 M | 3,824 M | -0.33% |

- [x] **`bun lint` with no config was 1.7% slower than `main`**, up to
5.5% in a folder of small files. None of it was in a rule. The built-in
config had grown from 5 to 10 patterns, so every file cost 20 object
tests and 16 pattern tests. Now an extension that no pattern can match
(`.md`, `.snap`, `.css`) returns at once, a `.js` file doesn't ask the
`**/*.ts` objects, and a pattern that ends in `/**` is asked once per
directory. This helps every ESLint-style config.
- [x] Threads merged the same set of config objects in parallel, each
sorting 1,600 global names twice, and every set was merged with and
without the React rules. Each set is merged once, and the lists of
globals are shared.
- [x] `-f unix` spent 610 instructions per line. It computed where a
finding ends, which it doesn't print, and searched the line table for a
line it already had. About a third of that now.
- [x] The default format linted a whole file again with every rule to
get the help of one problem it shows, and hashed each rule's name for
each finding.
- [x] A disable comment walked the whole list of rules for every rule it
names.
- [x] **`bun check`**: to sort a file's diagnostics, every comparison
looked up and converted both files' paths, about 360 instructions,
though nearly all pairs are from one file. 23 M of 4,000 M on 220 files
with 12,600 errors. The output is byte-identical.
- [x] The possible Jest calls of a test file are sorted as plain keys,
without a call per comparison: 17 M of 1,077 M on a folder of test
files.

- [x] `bun lint -f json` is 27% faster with 989 rules on 4,147 files
(10.89G instructions to 7.96G), and 34% faster under an ESLint config
with 218 rules (1,103M to 724M). For every file and every enabled rule,
the list of deprecated rules in use allocated the rule's name and
searched a table before it looked at the flag that says whether the rule
is deprecated at all. The output is byte for byte the same
- [x] Finding the line starts of a file was 2% of a `bun lint` run. It
is a Highway kernel now: 64 bytes at a time instead of 8
- [x] JavaScript plugins: see below
- [x] `Bun.Glob`: see below

#### New

- [x] `--init` adds `[lint]` / `[fmt]` to `bunfig.toml`
- [x] `bun lint --explain <rule>` prints the rule's page in the
terminal. `--rules` groups by plugin with descriptions. `--rules -f
json` has IDs, aliases, descriptions and defaults.
- [x] Rule names are clickable links in a terminal
- [x] `bun lint --doctor`, `bun fmt --doctor`: what runs natively, what
runs in JavaScript, which packages can go
- [x] A short `--help`. `--help --all` shows everything, grouped
- [x] A fresh `bun init` project passes `bun lint` and `bun fmt
--check`, in all four templates
- [x] `--staged`, `--changed[=<ref>]`
- [x] With both an ESLint and an oxlint config, oxlint's is used, with a
note. Same for oxfmt over Prettier
- [x] Bun's own messages in plain English

#### Docs

- [x] One page per rule: `docs/lint/rules/<plugin>/<rule>.mdx`, 1,021
pages plus a generated index
- [x] `test/cli/lint/rule-docs.test.ts` runs all 4,146 examples: what a
page marks as reported has to be reported, what it marks as fine must
not be. It also checks that every rule has a page and that the generated
frontmatter is up to date.
- [x] A generated `## Configure` section on 984 pages: how to turn the
rule on (or off, if it's on by default) in `bunfig.toml`. 407 of them
also list every option, set to its default, one per line. The names,
types and enum values come from the option schemas the linter validates
against. `bun lint --rules -f json` has `schema` and `default_options`
now. The test loads every snippet, and lints every example twice (rule
only, and rule with the options snippet): the reports have to be
identical, so a wrong default fails
- [x] `docs/runtime/lint.mdx` rewritten: 214 lines, was 1,265
- [x] `src/lint/CLAUDE.md`: how to write, register, document and test a
rule
- [x] `docs/runtime/format.mdx` rewritten: 295 lines, was 431
- [x] Migration guides in `docs/guides/lint` and `docs/guides/format`

Writing the pages turned up about 300 notes about rules and pages that
looked wrong. Each was checked against the original tool. The real bugs
in rules that are on by default are fixed here, and the pages say what
the rule does.

`rule-docs.test.ts` also runs all 1,512 `toml` snippets through `bun
fmt`, so what the docs show is what the formatter prints.

`docs/lint/rules` is in `.prettierignore`: Prettier reformats the code
in the examples, and many rules are about exactly that.

#### From review of #44805

- [x] Tables of 256 `bool`s are bit sets. `ArrayBitSet::set` and
`is_set` are `const fn`, and `bun_collections::ByteSet` (32 bytes) can
be a `static`. Scanning URL-like text: `[bool; 256]` 0.32 ns per byte,
`[u64; 4]` 0.50, the `match` that was there before 0.79 (it compiles to
a 376-byte jump table), `u128` 1.01. On a document that is 87% URLs,
that is under 3% of `Bun.markdown.html`. Sets of one to three bytes use
`strings::contains_char` / `contains_any`
- [x] One glob matcher. `src/glob` (without the directory walker) goes
from 9,235 lines to about 4,350. The ports of minimatch 10, minimatch 3,
picomatch and brace-expansion are gone, along with their hard-coded
limits. Lint and format convert other tools' patterns to Bun's syntax
and use the same matcher as `Bun.Glob`. Why this is safe: an
instrumented build asked `Bun.Glob`'s matcher the same question at every
real match call in 629 runs over 333 repos (1,870 patterns, 12.3 million
calls). 90.1% of patterns already gave the same answer, 1.0% needed
`?(..)` / `@(..)`, 8.8% differed only in what the caller passed in, and
2 patterns really differed. See "`Bun.Glob`" below for what changes
there

#### `Bun.Glob`

The matcher rewrite also changes `Bun.Glob`:

- **Extglob**: `?(a|b)`, `*(a|b)`, `+(a|b)`, `@(a|b)`, `!(a|b)`. A `(`
without one of `?*+@!` in front of it is still a plain character, so
Next.js route groups like `app/(marketing)/**` match as before.
- **Brace ranges**: `{1..3}`, `{01..10}`, `{a..e}`, `{1..9..2}`. The
number in the path is compared with the range. Nothing is expanded.
- **No limits**: braces used to stop working past 10 levels of nesting
or 10,000 branches (the match returned `false`). Matching no longer
recurses, so `+(a|b)` matches 100 KB of `ab`.
- **Bug fixes**: `{a,b/**}` matches `b/x/y`, `{**,a}/b` matches `x/y/b`,
and an unclosed `{a,b` is treated as literal text (it used to match `a`
but not `b`).

**Patterns that change meaning.** The new syntax takes some strings that
used to be plain text, as in picomatch, minimatch and bash with
`extglob`:

| Pattern | Before | After |
|---|---|---|
| `!(g)/a.ts` | Everything but `(g)/a.ts` | `a.ts` in any folder but `g`
|
| `**/!(*.test).ts` in `scan()` | Every file: a path component that
starts with `!(` matched everything | `.ts` files that are not
`.test.ts` |
| `"workspaces": ["packages/!(b)"]` | `error: Workspace not found` |
Every package but `b`, as in npm, pnpm and yarn |
| `*(1).txt`, `?(1).js` | `copy(1).txt`, `i(1).js` | Zero or more `1`,
then `.txt`. Write `*[(]1).txt` |
| A name with `+(`, `@(`, `?(`, `*(` or `!(` in `workspaces`,
`sideEffects`, `files`, `--filter` | That name | A group |
| `{1..3}` | The text `1..3` | `1`, `2` or `3` |
| An unclosed `[`, a trailing `\` | No match | Plain characters |

**Answers that were wrong in 1.4.3 and are right now.** Each was run on
the released binary.

| pattern | path | 1.4.3 | now |
|---|---|---|---|
| `{src/**,lib/**}` (`**` inside braces was treated like `*`) |
`src/a/b.ts` | `false` | `true` |
| `{**,a}` | `x/y` | `false` | `true` |
| `{a,b}` eleven times in a row (more than 10 brace groups) | `b` eleven
times | `false` | `true` |
| braces nested 11 deep | the innermost alternative | `false` | `true` |
| `a{` (an unclosed `{` is literal, as in bash and minimatch) | `a{` |
`false` | `true` |
| `{,` | the empty string | `true` | `false` |
| `*[!a]{,a}*` | `bc/` | `false` | `true` |

**How often this matters.** A search of public code (60 GitHub
code-search requests) found 334 patterns with one of these sequences in
a place Bun reads globs from: `new Glob(...)`, `workspaces`, `files`,
`sideEffects`, `.npmignore`, `bunfig.toml`, `--filter`. All of them use
`!(`. 331 clearly mean extglob, 3 are unclear, and none relies on the
old reading. About 13 are in repositories that use Bun. One test (in a
repository with one star) pins "`Bun.Glob` has no extglob" and will
fail. The search can't see patterns made at run time, private code, Bun
Shell, or `sideEffects` in published packages.

**File names.** Only the pattern is parsed, never the path, so a file
with such a name still matches `**/*.ts`. The one popular convention
that contains a sequence is SvelteKit's layout reset,
`+page@(group).svelte`: written out as a pattern, it no longer matches
itself (`**/+page*.svelte` does). None of the 137 public lines that
mention such a name is a glob. `@scope`, `@modal`, `+page.svelte`,
`(group)` and `(.)photo` are unaffected. `bun lint` and `bun fmt` take
the name of an existing file literally. On 12 patterns from that search,
`Bun.Glob` agrees with minimatch 10 on all 12, and with picomatch 4 on
8: on the other 4 the two libraries disagree with each other.

A `(` after anything else is still plain, so `Program Files (x86)`,
`code (old)`, `app/(group)` and `file(1).txt` work as before: 34
commands (install, run, test, build, pack, lint, format, ...) in each of
23 oddly named project folders behave as in a plain folder.

**Bun Shell is unaffected.** Quoted text, `${}` values and `$VAR` are
still data: `${"@()!(zzz)"}/*` matches nothing, and `"c++(old)"/*.ts`
finds the folder. 391,551 fuzzed shell runs give the same result as
before, except for symlinked folders whose name really contains `+(` or
`@(`.

All 80,016 pattern and path pairs in `test/js/bun/glob/match.test.ts`
give the same answer as before. Every pattern up to 6 characters long
from the glob alphabet (113 million patterns, 26 paths, both platforms,
every entry point, overflow checks on) runs without a panic.

**How it works.** A fast loop in front decides plain patterns and takes
plain brace groups inline. Behind it is one automaton over the pattern's
bytes: a single backward pass over the path with bit sets, where
`!(...)` is the NOT of a bit that is already known. A pattern that is
matched often (32 times, or once against a path of 512 bytes or more)
switches to a cache of the automaton's states that is built as paths are
matched. Matching does not recurse, and the time grows linearly with the
length of the path.

**Speed against Bun 1.4.3.** CI's LTO build against the released binary,
through `new Bun.Glob(pattern).match(path)`, user instructions per call,
143 pairs of a pattern and a path. "Reused" is one `Glob` matched many
times. "Fresh" is a new `Glob` for every match.

| | faster | level (within 0.5%) | slower | all rows together |
|---|---:|---:|---:|---:|
| reused | 142 | 0 | 1 | 2.7x faster |
| fresh | 141 | 2 | 0 | 1.5x faster |

| pattern | path | 1.4.3, reused | now | 1.4.3, fresh | now |
|---|---|---:|---:|---:|---:|
| `**/node_modules/**` | `a/node_modules/b/c.js` | 1,422 | 739 | 2,262 |
1,596 |
| `src/**/*.test.ts` | `lib/a/b/c.test.ts` | 400 | 349 | 1,230 | 1,107 |
| `{src/**,lib/**}` | `lib/a/b.ts` | 1,292 | 983 | 2,119 | 1,737 |
| `**/{src,lib}/**/{test,spec}/**/*.{ts,js}` |
`packages/a/src/x/test/y/z.ts` | 3,136 | 866 | 3,914 | 2,889 |
| `!**/node_modules/**` | `src/a.ts` | 625 | 509 | 1,471 | 1,469 |
| `*.[jt]s` | `a.ts` | 602 | 433 | 1,390 | 1,327 |
| `a/**/b/**/c` | `a/x/b/y/c` | 983 | 550 | 1,791 | 1,414 |

The rows that are slower:

| | pattern | path | 1.4.3 | now |
|---|---|---|---:|---:|
| reused | `!!a` | `a` | 346 | 359 |

Every version of the matcher that landed was first compared with the
previous one on 642 million pairs of a pattern and a path (107 jobs,
debug assertions on: the same counts per job, no loop, no panic), and
the last one on 1.1 billion more from tools aimed at its new fast paths.
Those tools were themselves tested with deliberate one-line bugs. They
found two wrong answers that three runs of the 642 million had missed
(`**/*[!a]*{a,b}` on `/abc/aa`), both fixed, with tests.

`scanSync()` over 50,000 files, same files found:

| Pattern | Before | After | Change |
|---|---:|---:|---:|
| `**/*.ts` | 157.1M | 155.1M | -1.2% |
| `**` | 423.9M | 420.5M | -0.8% |
| `p1*/src/**/*.js` | 95.7M | 95.5M | -0.3% |
| `**/*.{ts,tsx}` | 420.0M | 351.6M | -16.3% |

`bun install` in a 500-package monorepo with `workspaces: ["packages/*",
"apps/**"]` is within noise (+0.3% to +0.8%, noise 0.5%).
`packages/!(internal)`, `apps/@(web|api)` and `libs/lib{1..2}` work as
workspace entries. Every place that asks "is this string a glob?"
(workspaces, `sideEffects`, `bun pm diff`, the walker's literal fast
paths, the kernel filter on Windows) knows the new syntax.

The old `src/glob` still compiles in a test harness, so old and new were
compared in one process: 10.2 million ignore lines for oxlint and oxfmt
(1 differs, and there the new code matches real oxlint), 4.3 million
override and `.editorconfig` patterns (0 differ). At the level of the
product, 16,275 patterns went through each of 36 config options, one
process each: 19 options are identical, and the rest differ on 1 to 104
broken patterns (`*]`, `(*)`, a bare `|`, unbalanced brackets) where the
old code reproduced quirks of old minimatch versions.

#### JavaScript plugins

Third-party ESLint rules (`plugins` in an `eslint.config.js`,
`jsPlugins` in an `.oxlintrc.json`) used to run in a 5,528-line
JavaScript program embedded in the binary. It reimplemented ESLint's
rule API on top of arrays of numbers that Rust serialized and copied
over, on separate threads that the lint threads waited for.

- **The rule API is native.** `TokenStore`, `SourceCode`,
`context.report` and the fixer, the scope manager's objects, code path
analysis, selector matching and the order of listener calls are C++ and
Rust. Objects are made from Structures that are built once and filled by
offset. `code_path.js`, `report.js`, `tokens.js` and `source_code.js`
are deleted, 1,976 lines of JavaScript are left, and about 500 of those
only call other people's JavaScript (the project's own ESLint, Prettier
and processors).
- **JavaScript runs on the thread that lints the file.** A thread that
has a file with JavaScript rules owns a VM and does everything for that
file: parse, built-in rules, plugin rules. How many threads get a VM
still depends on memory and on how much work is left. The extra threads,
the hand-off between them and the wake-up of every lint thread per file
are gone.
- **Nothing is copied.** Native code reads Rust's tables for the file in
place. The spans are cleared before Rust frees anything, and native
methods only ever look at the current file's state, so an object that a
plugin keeps from an earlier file can't reach freed memory.
- **Only declared listeners are called, from a finished list.** Rust
works out which listeners get which node, in ESLint's order, with the
code path events merged in. The JavaScript that's left is one loop over
that list.

Instructions, release builds, lower is better. "Before" is #44805 as
merged. Both builds were run alternately in one sitting, 4 threads,
lowest of 3:

| Run | Before | After | Change |
|---|---:|---:|---:|
| 199 ESLint core rules loaded as a plugin, 262 TypeScript files |
51.16G | 33.08G | -35% |
| A rule that listens for all seven code path events, 2,000 files |
26.73G | 9.99G | -63% |
| A rule that walks every scope, 2,000 files | 17.34G | 9.89G | -43% |
| `getScope` on a few nodes, 2,000 files | 8.72G | 9.08G | +4% |
| A rule that listens for `*`, 2,000 files | 11.86G | 6.32G | -47% |
| `context.report` on every identifier, 2,000 files | 12.92G | 8.87G |
-31% |
| A report with merged fixes and a suggestion, 2,000 files | 34.04G |
21.49G | -37% |
| A rule that visits every `Identifier`, 200 small files | 173.2M |
100.3M | -42% |
| The same, plus `getTokenBefore` and `getTokenAfter`: cost of the two
calls | 38.4M | 7.8M | -80% |
| 12 token methods at every node, 200 small files | 597.3M | 192.1M |
-68% |
| A plugin that does nothing, 200 small files, 1 thread | 114.6M | 63.1M
| -45% |
| A plugin that does nothing, 1 file, 1 thread (start-up) | 80.8M |
33.5M | -59% |

The first row is noisy: the old build against itself differs by 4%
there, and its three runs of the second row by 6.5%. The three runs of
every other row are within 0.9% of each other on the new build. The
report of the first row is the same size to the byte on both builds. The
row with a suggestion prints 8% more JSON on the new build, because a
suggestion's `data` is passed through now.

| 1,200 files, one small plugin, 64 threads | Before | After | Change |
|---|---:|---:|---:|
| Context switches | 75,757 | 8,719 | -88% |
| Peak memory | 265 MB | 151 MB | -43% |

Slower:

- A rule that calls `getScope` on a few nodes: +4%.
- `sourceCode.getText(node)`: +0.7% against the JavaScript it replaced
(the JIT inlines `text.slice`, and a native call can't beat that).
- Nodes with the exact layout of espree and typescript-estree cost 1.2
to 1.4% more to build than the layout before, because `loc` is an own
property now. Reading `loc` is 5% faster.
- Wall time for one small plugin at 4 threads with 3 VMs: 5 to 10% more,
because no spare thread parses ahead any more.

**Closer to ESLint.** Everything was compared with real ESLint 10.12
(espree, and `@typescript-eslint/parser` 8.71.1) and real oxlint 1.87
over about 63,000 inputs. That turned up places where plugins could see
a difference, now fixed:

- Nodes: own keys, their order, attributes, prototypes and `loc` now
equal espree's and typescript-estree's. Whole trees are byte-identical
in 63,185 of 63,195 files, and `visitorKeys` is byte-identical. Under an
oxlint config, the layout of every node type equals oxlint 1.87's in all
25,658 TypeScript files that it parses.
- Scopes: own keys, their order, attributes and class names now equal
`eslint-scope` and `@typescript-eslint/scope-manager` in all 25,765 and
37,428 files. In a first sample of 418 files, none matched. Values are
identical in 25,763 and 37,415. `thisFound`, `taints`, the order of
references, `getDeclaredVariables` and names from `/* eslint-env */`
comments were wrong. `thisFound` made
`unicorn/consistent-function-scoping` report arrow functions that use
`this`.
- Tokens and comments: the three layouts (espree, typescript-estree,
oxlint), positions that aren't token boundaries, negative `count` and
padding. Every method with every option form at every node, token,
comment and text index: 63,184 of 63,193 files are identical.
- `context.report`: a report whose `line` or `column` isn't a number was
dropped silently. ESLint's order of reads, `RuleFixer` as a class, a
suggestion's `data` passed through.
- `SourceCode`: ESLint's ten own frozen properties in its order. `loc`
of nodes in each parser's layout.
- Listeners get `undefined` as `this`, as in ESLint. They got an
internal object.
- When a rule throws, the error of the first path is reported. Which one
it was depended on timing.
- A plugin that puts an accessor with an index for a name on
`Array.prototype` crashed the process (also in #44805).

The 9 files that still differ everywhere are Flow syntax in `.tsx`,
where the syntax tree differs.

#### Visible outside `bun lint` and `bun fmt`

- `Bun.Glob`, and everything that uses it: see above.
- **`Bun.write(Bun.stdout, new Response(asyncIterable))` was a
use-after-free** when the reader of the pipe left while a write was
parked (ASAN: heap-use-after-free in the pipe writer). The writer keeps
its parent alive until `close()` returns. Same bug as #34697
- **`Bun.spawn({ terminal })` could hang forever on macOS** in a
blocking `wait4` on the JavaScript thread, when kqueue refused the exit
watch. A port of #41732. Fixes #42171
- The TypeScript lexer behind `bun check`, `bun lint` and `bun fmt` used
`std::simd`. It uses Highway like the rest of Bun, and `std::simd`,
`core::simd` and `feature(portable_simd)` are banned by clippy and a
source lint
- `warn:` is bold yellow in all of Bun's error output. It was dim.
- The `^` under an error is in the right column when the line has wide
characters (CJK, emoji).
- `Bun.markdown.ansi` and `bun file.md`: a word that arrives in pieces,
like `` `code` `` followed by `.` or `(` followed by a link, is no
longer split at the end of a line. The break goes to the last space.
- `toHaveBeenCalledOnce()` is in `bun-types`. The matcher already
existed.
- A project's own `lint`, `format` or `check` script, file or binary
still wins over the built-in command. `--help`, `-h`, `--help-all` and
`--doctor` (and `--explain` for `lint`) now go to Bun, since no other
tool has the last three and the migration guides send people there who
still have `"lint": "eslint ."`. Everything else, `-v` and `--version`
included, reaches the script.
- `bun init`: the templates pass `bun lint`, `bun lint --type-aware`,
`bun check` and `bun fmt --check`. The code that changed is formatting,
types, `async` dropped from route handlers that don't `await`, and an
unused `req`. `frontend.tsx` compiles to the same bytes as before in a
plain transpile, an unminified build, with `--react-fast-refresh` and in
the dev server's own transform. Every route answers with the same
status, headers and body.
- Shell completions for `lint` and `format`.
- Start-up is unchanged: `bun -e 1` +0.33% instructions, `--version`
-0.22%, an empty file -0.12%, 20 Workers -0.11%, 1,000 ShadowRealms
-0.14% (two runs of one build differ by 0.1 to 0.3%).

#### Binary size

Against `main`, in CI (the limit is 512 KB):

| target | |
|---|---:|
| darwin-aarch64 | +244.9 KB |
| darwin-x64 | +238.4 KB |
| linux-aarch64 | +320.0 KB |
| linux-x64 | +260.0 KB |
| linux-aarch64-musl | +256.1 KB |
| linux-x64-musl | +256.1 KB |
| linux-aarch64-android | +384.1 KB |
| linux-x64-android | +292.1 KB |
| freebsd-x64 | +240.1 KB |
| freebsd-aarch64 | +248.1 KB |
| windows-x64 | +349.0 KB |
| windows-aarch64 | +356.5 KB |

The rule pages for `--explain` are 304 KB of that, compressed. They're
prose and examples: zstd at its highest level, xz and brotli all end
within 3% of each other.

- Text that only `bun lint`, `bun fmt` and `bun check` read is
zstd-compressed in the binary: the rule pages, option schemas, presets,
`bun check`'s 1,371 messages, oxlint's help and the JavaScript for
plugins. That saves 432 KB. It's inflated on first use, which costs 146
to 202 µs for `bun check`'s messages and 1.3M instructions when a plugin
starts. Nothing the runtime loads is compressed. Text that an ordinary
run would have to inflate (the names of globals, oxlint's category
tables) is left as it is: 67 to 131 µs each.
- `Report::fix`, `suggest_as`, `labels_with`, `help_with` and
`hint_with` were compiled once per closure: 832 copies, of which about
300 bytes each were the same code. That part is out of line now. 184 KB
on a build without LTO, 241 to 276 KB per target in CI. A rule that
reports nothing runs the same instructions as before, and a report with
a fix costs 50 to 85 more.
- 12 sorts in cold rule code share one implementation: 84 KB. For each
unstable one there's a reason why ties can't be seen. Two that turned
out to run in every oxlint-config or typed run were put back.
- Standard-library sorts compiled once per closure and `JSMap::set`
inlined five times in the plugin host: 62 KB.
- The three accessors for a file's scopes, variables and references are
inlined in about 1,650 places, and each copy carried two cold blocks.
They share one out-of-line exit now: 43 KB, and the common path is one
instruction shorter.
- `#[optimize(size)]` on 258 functions that never run for a file or a
config without errors: `--doctor`, `--explain`, `--init`,
`--print-config`, `--rules`, `--debug-check`'s comparison, and the
functions that put a parser's error into oxlint's or ESLint's words.
About 30% off each, 95 KB together. The rule is written next to each
`#![feature(optimize_attribute)]`. Every function that got it had its
callers read, and three that turned out to run on ordinary paths lost it
again.
- The constructor for a syntax error was generic with about 140 call
sites. It's a thin wrapper around one cold body.
- **The shared sorts (`src/collections/index_sort.rs`) had 270 copies of
297 bytes**, most of them on `main` too. 190 of those bytes build the
list of indices, which doesn't depend on the element type, and every
comparison closure was compiled twice, because the vtable of a `&mut dyn
FnMut` also has a `call_once` slot that nothing calls (230 unused
bodies). 64 KB. The algorithm, the indices and the comparisons are the
same, so ties can't change. All seven entry points were compared with
the standard sorts at lengths 0 to 5,000. The bundler, the installer and
the runtime use these sorts too: a bundle of 3,000 modules costs the
same (-0.1% to +0.04%).
- Why that last one was needed: the arm64 Linux files grow in steps of
64 KB, because a section is aligned to that. `linux-aarch64-android`
read +448.1 KB and had 20,448 bytes left before a step to +512.1 KB,
which fails the check by 72 bytes.

#### Removed

- **Two source lints added by #44805**:
`test/internal/source-lints/shared-helpers.test.ts` and
`inner-allows.test.ts`, with their inventories (about 1,640 lines).
`shared-helpers` flags functions by name (`trim`, `quoted`, ...)
anywhere in the repo, and `inner-allows` is a repo-wide policy on
`#![allow(..)]` with an inventory of code this project doesn't own. They
were useful while #44805 was being written, but as permanent CI they'd
mostly get in other contributors' way. The other two lints from #44805
stay: `sema-parser-recursion` (guards against a real stack overflow) and
`shared-sorts` (protects a 228 KB size saving, only looks at
`src/format`).
- **`LICENSE.md`**: the rows from #44805 were audited against the tree.
Rows for code that no longer exists are gone (the Svelte printer, the
`vue` and `jsdoc` rules, minimatch, picomatch, brace-expansion), one
wrong project was corrected, and about 30 missing credits were added.
`code_path.js`, which is mostly ESLint's code, now carries ESLint's MIT
notice.

### How did you verify your code works?

- Every item ticked above was run on a release build of this branch, on
made-up projects, the way a person would use it, including on a
pseudo-terminal.
- New test files: `defaults`, `hints`, `init`, `doctor`,
`format-doctor`, `explain`, `help`, `output`, `native-rules`,
`messages`, `rule-docs` under `test/cli/lint`, and `bunfig`, `words`
under `test/cli/format`.
- The upstream suites from #44805 are unchanged and pass.
- React defaults cost nothing measurable when they don't apply: 868 M
instructions against 863 M on 3,000 `.tsx` files in 600 directories, and
the same number of system calls.
- With an ESLint config (9 output formats) and an oxlint config (10),
output before and after the hints is byte for byte the same.

- **Real repositories.** The merged build against this branch on 333
open-source repositories, each with its own config, arguments and
installed `node_modules`, in a sandbox: 629 runs (204 oxlint, 108
ESLint, 243 oxfmt, 74 Prettier). 627 are identical in stdout and exit
code. 1 is the `thisFound` fix above (discord.js: 4 false positives
gone). 1 is a `.toml` file that's now formatted in a project with no
Prettier config file. An earlier pass found a regression in 13 runs (an
extra `data` key on `react-hooks/exhaustive-deps` suggestions in `-f
json`), which is fixed. This pass ran after the native plugin host was
complete.
- **199 ESLint core rules as a plugin on 262 TypeScript files**: real
ESLint and this branch agree on all 60,785 messages, in rule, position,
text and fix.
- **Each native piece** went in behind a switch, was compared with the
JavaScript it replaced and with the real tools, was made the default,
and the JavaScript was deleted one green build later.
- **Debug + ASAN** with leak detection and
`BUN_JSC_validateExceptionChecks=1` before each deletion: the JavaScript
plugin, parser, processor and Prettier plugin tests, plus an argument
fuzzer for each native function (wrong types, Proxies, throwing getters,
callbacks that call back in, objects kept from an earlier file, calls
after the file has ended, forced GCs, low JIT thresholds).
- **Config matching was reworked for speed**, so it was compared before
and after on 13,600 real files under five kinds of config, and on a
made-up tree of 6,300 files (25 directories, 18 kinds of name, 14
extensions) under seven configs, with 1 and 8 threads: 22 runs, 150,000
lines of findings, all byte-identical. In debug builds every shortcut
recomputes the full answer and compares.
- **Every speed claim** is user instructions on CI's LTO builds, `main`
at the merge base against this branch, alternating, best of 3 or 4.
Causes were found with exact counts (callgrind on both builds), not from
samples: two sampled profiles pointed at the wrong functions.
- **Three more reviews with the one aim of breaking the last day's
work**, on the built binary, reporting only what reproduces. CI was
green and the review bot had found nothing.
- *Config matching*: 2,170 before-and-after pairs (206 hand-picked
patterns, 291 as overrides, 1,400 random configs from a grammar, either
side of every limit, a React monorepo with packages nested both ways,
files named `.js`, `a..js`, `a{b,c}.js`, `a*.js` and with invalid UTF-8)
and 290 runs at 64 threads. Nothing.
- *The Prettier plugins*, with real Prettier and the real plugins as the
oracle: 20,000 classes in one attribute, 30 odd attribute shapes, 13
hostile Tailwind configs, monorepos, 11 odd folder names. No data loss,
crash, silent unsorted output or nondeterminism. Found seven bugs at the
edges, all fixed: `--allow-unsupported` turned off the `package.json`
hand-off, so it wrote other bytes than `bun fmt`; `""` in a path option
was read as a path; `null` was accepted; a refusal blamed JSON and not
the plugin; one run said a plugin has no effect and refused files
because of it.
- *Positions and output*: 772,330 messages equal to real ESLint's in
line, column, end line and end column, 983,030 findings under an oxlint
config equal in 14 formats, files of 63 to 4,097 lines with the only
non-ASCII line at every edge, 60 open-source projects. Found that the
faster `-f unix` printed `2:7` for a plugin's `loc` past the end of a
line, where oxlint and every other format say `3:3`. Fixed. Found the
order under `overrides` above.
- **Threads**: 8 configs at 1, 4, 16 and 64 threads give one report hash
per config. 600 stress runs with a timeout had no hang.
- **A final review in five passes**, with CI green and the 333
repositories identical, each looking for what all of that had missed:
- *As a first-time user*, on seven made-up projects and the four
templates. Found the false errors in "Default rules". Second round:
every error left in the code projects is a planted bug, and none of the
fixes cost a real catch (16 hook misuses, 7 of 7 stray characters in
code, 7 kinds of real fallthrough are still reported).
- *As someone migrating*, about 980 commands with real plugins, most of
them three ways (real tool, `main`, this branch), comparing stdout, exit
code, and the hash, mode and inode of every file. No regression under
any ESLint, oxlint, Prettier or oxfmt config. Found the `--parser` data
loss and the oxlint gaps above. 63 path idioms with 4 tools, 30 stdin
shapes, 26 `--fix` flag combinations: Bun never writes a file the real
tool wouldn't, apart from "no arguments means the current directory".
- *The plugin host's memory safety.* Found two segfaults, the abort, and
two ways for a plugin to reach the host's internals, all fixed. Then:
2,250 fuzz seeds (hostile arguments, Proxies, re-entrant callbacks, 21
kinds of prototype pollution), 3,600 runs at 2 to 64 threads, VMs freed
mid-run, objects kept from earlier files under ASAN with forced GCs, 22
odd encodings, 144 very deep files: no crash, no deadlock.
- *`Bun.Glob` and everything that uses it.* Found that quoted text in
Bun Shell had become glob syntax, and two `.prettierignore` lines that
differed from Prettier, both fixed. Found that `match()` had become
quadratic in the length of the path, and then an endless loop and wrong
answers in the first fix for that. All fixed: matching is linear, and
see "Speed against Bun 1.4.3". Then: every pattern of up to 5 tokens
(6.7M patterns, 64 paths), 111M fuzzed pairs of well-formed old syntax
(22 patterns differ, and there the old answer was the bug), 151M
crash-fuzz pairs, 623,616 `scanSync` calls over all 32 option
combinations, 54,240 ignore lines against the npm package (0 differ).
- *Everything outside lint and format.* Found that flags skipped a
project's own `lint` script, and the two commands that wrote files.
Then: 11 project shapes, 3 commands and 65 command lines against `main`
and 1.4.3, a 253-command smoke comparison, 16 bunfig files with 10
commands: only the differences listed above.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Jarred-Sumner added a commit that referenced this pull request Oct 20, 2026
… and CLI (#46021)

### What does this PR do?

Hardening. This collects the open pull requests that fix a crash in Bun
into one change, and fixes about 20 more crashes that had no pull
request.

"Crash" here means a segfault, a Rust panic, an abort, a failed
assertion, memory corruption that a sanitizer reports, a native stack
overflow, or an exception that ends the process and that the program
can't catch. With this PR those cases throw a normal error, print a
normal CLI error and exit 1, or just work.

306 pull requests are included: 227 whole, and 79 cut down to the crash
fix where the rest was a refactor, a feature or a behavior change. Each
one was checked against current `main` first. 45 more turned out to be
fixed already, and 17 were duplicates. The full list is at the bottom.

#### Crashes you could hit in normal use

- **`bun build` with macros and a `.env` file crashed at random.** In a
repro with many macro modules, more than a third of the builds crashed.
Now 3,000 of 3,000 produce the right bundle. (#45960)
- **`bun run` and `bunx` aborted if a signal arrived while the child was
being spawned.** (#38926, #45965)
- **`bun build --compile ./index.js ./public/*` panicked** if an
embedded file's name wasn't valid UTF-8.
- **A truncated or corrupted compiled executable** died with SIGBUS or a
panic at startup. It now prints an error. (#31787, #38251, #41360)
- **Dev server:** several `Option::unwrap()` panics after a failed or
deleted import (#38046, #44744, #44746), a segfault when an `onLoad`
plugin throws while another bundle is queued, a request that hung and
then panicked with `bundle active`, and `server.stop()` that never
resolved after a client aborted a waiting request.
- **`Bun.serve`:** `server.fetch(url, { headers: new Headers() })`
followed by a GC segfaulted (#40888). Routes were used after free after
`server.reload()` with `tls.serverName` (#38636).
- **`text()` and `json()` on a stream of string chunks** could abort the
process, a regression in 1.4.0. (#44269)
- **`Bun.Transpiler` with `exports.eliminate` or `exports.replace`**
aborted on `export default 1` and on most re-export clauses. (#44137)
- **A decorated `declare` field in a class expression** with
`experimentalDecorators` panicked. (#38095)
- **YAML and JSON5 files with a key that isn't a string** panicked with
`--no-bundle` and in `Bun.Transpiler`. (#41827)
- **`Bun.FileSystemRouter`:** reading `.params` segfaulted when a
rejected route candidate left its parameters behind. (#39290, #39291)
- **Native addons that call `uv_async_*`, `uv_timer_*`, `uv_idle_*`,
`uv_prepare_*`, `uv_check_*`, `uv_queue_work` or `uv_cwd`** aborted with
"unsupported uv function" on Linux and macOS. They're implemented now.
(#36609, #39652, #39892)
- **`--watch` and `--hot`** panicked when the system was out of inotify
instances or file descriptors, or when the reload `exec` failed. They
print an error now. (#39629, #39975, #44837)
- **Paths longer than the path buffer** panicked in `bun install`, the
resolver, the bundler, `--compile`, `tsconfig.json` `paths` and
`baseUrl`, `package.json` `main` and `sideEffects`, `bun run --filter`,
`bun pm diff`, source maps and snapshots. They're ordinary errors now,
or they work. (#36340, #37529, #39104, #39650, #43067)
- **A Worker that creates a `ShadowRealm` and imports
`node:worker_threads` in it** segfaulted.
- **`structuredClone` or `postMessage` of an X25519 key** gave an object
that aborted the process when read. (#45624)
- **`node:stream` web adapters and `node:http2`** could end the process
with an exception that no handler could catch. (#45076, #45975)
- **Windows:** a watcher panic in a burst of file changes (#44344), a
segfault after the machine resumes from sleep (#33015), crashes in the
shell's pipe reader (#39638, #43606), and addons that import from
`node.exe` without the delay-load hook (#35618).

Most of the rest needs unusual input: strings near the 2 GiB limit,
buffers that another thread or a getter resizes or detaches in the
middle of a call, `worker.terminate()` at a bad moment, running out of
memory or file descriptors, very deep nesting, or hostile arguments to
`bun:ffi`, `node:vm` and `bun:sqlite`.

#### Behavior changes

Things that didn't crash before and behave differently now:

- `new` on native functions that aren't constructors throws a
`TypeError`, as in Node: `util.types.*`, `buffer.isAscii`, `isUtf8`,
`transcode`, `resolveObjectURL`, `bun:jsc` exports, `cc()` symbols. It
used to return the call's result. They also stop printing as `[class
hostname]`. (#34575)
- `` $`cmd` `` throws `ERR_INVALID_ARG_VALUE` if an environment
variable's name or value contains a NUL byte. It used to cut the value
at the NUL. (#44981)
- `cc()` functions throw a `TypeError` for arguments that used to reach
C as garbage, and `read.*(ptr, NaN)` throws. (#37989, #38057, #40773)
- As PID 1, `bun` exits with 128 + the signal number on Ctrl+C or
`docker stop`. (#38877)
- A `NODE_MODULE` addon that's already loaded by the main thread throws
`ERR_DLOPEN_FAILED` when a live Worker loads it too, as in Node.
(#39968)
- An exception from a `node:vm` context reaches `uncaughtException`
handlers. (#39992) `vm.constants.DONT_CONTEXTIFY` returns the real
global proxy. (#34623)
- `createPrivateKey` rejects an EC JWK whose private value doesn't match
its public point. (#33752)
- `@dec static {}` is a syntax error, as in TypeScript and esbuild.
(#44883)
- `clearTimeout` ignores 0 and negative ids, and timer ids no longer
wrap. (#44771)
- HEAD for a `Response` whose body is an S3-backed `Blob` reports the
length that GET sends. (#44734)
- `bun:sqlite` and `node:sqlite`: if `iterate()` left a write unfinished
on a connection that has a hook, a user function or an authorizer, the
write is finished on the connection's next call instead of during
garbage collection. If the database is gone too, it's rolled back.
- `bun test --bail` runs exit listeners and closes SQLite databases.
(#39010)
- Dev server: a request for a client script waits while a bundle is in
flight (#42733), query strings reach framework routes (#33232), and a
request gets a 500 instead of hanging when plugins fail (#36812).

#### File formats

- `.jsc` bytecode files get a 24-byte footer so they can be verified
before decoding. Files from an older Bun are ignored and the source is
parsed instead. (#39396)
- `node:vm` `cachedData` gets an 8-byte checksum. A blob from an older
Bun is rejected, which the API allows. (#32839)
- The built-in modules section of a compiled executable changes from
format 1 to 2 and carries an engine stamp. (#44907)

#### Performance

Measured in instructions per operation on release builds of this branch
and its base, with an A/A run for the noise floor (0.0 to 0.2 %).

No change: `Bun.serve`, `node:http`, WebSocket echo and publish, `bun
build` of 3,807 modules, `bun run` with 2,000 imports, `readdir` /
`Glob` / `fs.cp` over 23,689 entries, startup and RSS. The binary grows
by 176 KB (0.17 %).

| Faster | Instructions |
| --- | --- |
| WebSocket echo of a 1 MB non-ASCII text message | −72 % |
| `Bun.inspect` of a large non-ASCII string | −39 % |
| `Bun.markdown.html` on large non-ASCII input | −33 % |
| `` $`cmd` `` with 300 environment variables | −6 % |
| `fs.readSync` | −5 % |
| `TextEncoder.encodeInto`, short ASCII strings | −4 % |
| async `crypto.pbkdf2`, 16-byte inputs | −17 % |

| Slower | Instructions | Why |
| --- | --- | --- |
| `cc()` calls | +5 to +51 per call | Argument count and type checks,
and a check for `close()` (#37989, #38057, #43802, #44921). `dlopen()`
calls don't change |
| `process.env.X = v` | 38 → 593 per write | Writes aren't cached. Reads
don't change (#38871) |
| async `crypto.pbkdf2`, inputs of 1 KB or more | +4 to +9 % | Password
and salt are copied (#40554) |
| `bun build` with an object `--define` used thousands of times | +4.5 %
| The object is copied per use (#45969) |

#### Not included

- Fixes that need a WebKit change: #39967, #42534, #42982, #43764,
#43786, #44226. #42185 too: a typed array that has no `ArrayBuffer` yet
can't be pinned, so `view.buffer.transfer()` during an async call can
still free its bytes. Creating the `ArrayBuffer` up front costs 7 to 12
% on every async `fs` call, so the fix belongs in JSC: an `ArrayBuffer`
created while the view is borrowed should start out pinned.
- #45442 (`calc()` sums as a flat list): it changes minified output for
real stylesheets to survive a `calc()` with 25,000 terms. It deserves
its own review.
- #40023 (Windows event loop redesign), #29928 (Windows exit path),
#40534, #43963, #39571, #42904, #42834, #36355, #43266: refactors or
features whose crash is already covered or isn't a crash.
- The pull requests marked *(crash fix only)* below should stay open for
their other half.

### How did you verify your code works?

- **Tests.** Every fix has a test that fails on `main` (a release or an
ASAN build) and passes on this branch, except where that isn't
practical: code that only runs on Windows or macOS, inputs that need
several GB of memory, and a few rare races. Those were checked by hand
or by reading.
- **Stored repro scripts.** 230 crash repros ran on release and ASAN
builds of this branch and of `main`, side by side. Release: 88 no longer
crash. ASAN: 106 no longer crash. None crashes that didn't before. What
still crashes needs WebKit, is SQLite's own bug, or isn't a crash. The
ASAN number is from a later commit than the release number.
- **Dev server.** Because one fix makes requests wait, 2,171 generated
programs ran random interleavings of edits, build errors, failing
plugins, reloads, stops and disconnects with about 120,000 requests. No
request hung, was answered twice or got a stale body. `main` hung in 82
of 1,161 programs. This also found the four dev server bugs listed
above.
- **Path helpers.** 336,000 boundary cases with buffers of exactly the
computed size, and 12,003 random calls through 30 JS APIs on an ASAN
build, compared with `main`. No sanitizer report, and the results match
wherever `main` doesn't panic.
- **What worked on 1.4.3 still works.** Reviewers compared behavior with
1.4.3 and took out what changed it: for example an output directory
layout change for 9 or more entry points, a `server.reload()` change,
and a changed error message for `import("file:///50%deposit.ts")`.
- **Not run locally:** the Windows, macOS and FreeBSD code paths. CI
compiles and tests them.

### Included pull requests

**Bundler, transpiler, CSS, macros** (33)

- #33881 bundler: allocate wrapper_ref for CommonJS modules with no
non-hoistable statements
- #35055 Bun.build plugins: handle filter RegExp flags beyond i/m/v
- #37769 bundler: fail the build instead of panicking when the bundle
thread cannot create its waker
- #37784 bundler: copy inlined env values into the define arena, and
give each Bun.build its own env copy *(crash fix only)*
- #37858 bundler: fail the build instead of panicking when a plugin
answer string cannot be converted
- #38046 bun build --server-components: require the bun target and
reject directives without a framework *(crash fix only)*
- #38095 js_parser: fix panic on decorated declare/abstract fields in
class expressions with experimentalDecorators
- #38966 bundler: keep deep CSS, export star and composes graphs from
overflowing the linker's stack
- #38984 bundler: stop an export star ambiguity that loops back into a
re-export chain from overflowing the stack
- #39113 css: reject stylesheets of 2 GiB or more instead of aborting on
an int cast
- #39396 bundler: frame .jsc bytecode sidecars and verify them before
decoding
- #39855 bundler: join the work still on the pools before the bundle is
torn down *(crash fix only)*
- #41157 dev server: leave out an html link to a cached json module
instead of panicking, and mark a new placeholder file stale
- #41801 css: decode ill-formed UTF-8 to U+FFFD before tokenizing
*(crash fix only)*
- #41827 bundler: handle YAML and JSON5 keys that are not strings
instead of panicking
- #42242 js_parser: compress symbol link chains when following merged
declarations
- #42387 bundler: check receivers on the Bun.build plugin object and
freeze its filters during a build
- #42413 Bounds-check the InternalSourceMap window reader
- #42657 macros: keep visited values alive so a reused address does not
get another value's Expr
- #43330 transpiler: do not print an empty `var` for a data file with no
named export
- #43355 bundler: fix "The memory limit has been exceeded." on large
HTML entries
- #43658 react-compiler: fix skipped functions and build aborts for dead
code in a try body *(crash fix only)*
- #44137 js_parser: fix four crashes of exports.eliminate and
exports.replace
- #44467 js_parser: replace skipped expressions with E::Missing and skip
argument checks after a stack overflow
- #44662 js_parser: walk binary chains on the heap and check the stack
when rewriting decorated #private accesses
- #44712 json5: reject sources of 2 GiB or more before parsing instead
of aborting on an int cast
- #44864 js_parser: walk conditional chains in import()/require() and
define keys in a loop
- #44883 js_parser: reject a decorator on a class static block, keep
decorators out of the body of `declare global` *(crash fix only)*
- #45045 Fix a segfault in new Bun.Transpiler(): re-point options.log
after the constructor moves its Log
- #45604 css: keep a url() in an at-rule prelude as written, and never
print the resolved path of a url() *(crash fix only)*
- #45748 bundler: put --banner/--footer in the bytecode ESM module
record (flags from a parse, entries from JSC) *(crash fix only)*
- #45960 macros: give each parse-worker macro VM its own env loader
- #45969 js_parser: copy object and array defines per use, and copy the
list of a lone JSX spread object *(crash fix only)*

**`bun build --compile` and standalone executables** (3)

- #31787 Don't crash at startup when a standalone executable's embedded
graph is corrupted *(crash fix only)*
- #38251 compile: exit with an error instead of SIGBUS when a standalone
executable is truncated
- #41360 standalone: check every offset in the embedded module graph
before reading it

**Resolver, module loading, plugins, paths** (25)

- #32269 Bun.plugin: validate the namespace without a shared regex
- #33183 bun:jsc: filter internal cells out of getProtectedObjects()
- #34575 Don't register native functions as their own constructors
- #36340 paths: size the thread-local join output buffers to
MAX_PATH_BYTES on Windows
- #37037 mock.module: reject async factory results that are not objects
- #37065 bun:jsc: propagate JSONParse exceptions from
samplingProfilerStackTraces
- #37529 resolver: don't abort on a package.json sideEffects entry
longer than the join buffer
- #38179 node:module: throw instead of crashing when module._compile is
set to a non-function
- #38273 bun test: report a test file or preload the loader cannot
resolve instead of exiting; keep the JUnit report valid U… *(crash fix
only)*
- #38732 paths: compute the common path of 9+ inputs with the same loop
as fewer *(crash fix only)*
- #39228 paths: strip C:\\ down to the drive root in
without_trailing_slash_windows_path *(crash fix only)*
- #39650 bun run --filter: stop panicking on workspace paths longer than
the path buffer
- #40186 resolver: stop deeply nested exports targets from overflowing
the stack
- #40258 resolver: publish Entry.abs_path through the per-entry mutex
- #42183 node:module: reject a _resolveFilename override result that
contains a null byte
- #42401 node:module: accept any `this` in Module.prototype.require
*(crash fix only)*
- #42405 Bun.plugin: transpile a copy of typed array onLoad contents
- #42414 node:module: end the Module._stat path at the first null byte
- #42685 resolver: strip the trailing separator inside bust_dir_cache
- #42735 Throw a RangeError instead of aborting when require.resolve
paths or Worker preload outgrows its Vector
- #43067 Report a path that does not fit a path buffer instead of
aborting *(crash fix only)*
- #44410 Fix a crash when code from a node:vm context reads
require.cache or require.extensions
- #44466 Trace the value an object or data module exports from its
JSSourceCode
- #45044 Bun.plugin: give onLoad's args.path its own bytes
- #45117 cjs: do not call an `__esModule` getter during the annotation
lookup

**Dev server, `bun bake`, routers, `--watch` and `--hot`** (28)

- #28793 Stop file watcher thread before Global.exit tears down memory
*(crash fix only)*
- #32143 bake: fix "Runtime file not found" panic in production builds
of custom frameworks
- #32443 watcher: don't free the Watcher in the spawn-to-start window
*(crash fix only)*
- #33232 bake: normalize the HTTP request-target before matching
framework routes
- #36812 bake: respond 500 and release both RequestContext refs when
on_plugins_rejected / OOM drains a deferred framework r…
- #37039 bake: report per-file print failures in the dev server instead
of serving empty modules
- #37276 hot_reloader: take entries_mutex for watcher-thread directory
cache probes
- #37444 bake: unregister Bake::SourceProvider from the source map table
when it is destroyed
- #39290 FileSystemRouter: match / against a root-level optional
catch-all route *(crash fix only)*
- #39291 FileSystemRouter: order dynamic routes by per-segment
precedence like Next.js *(crash fix only)*
- #39629 watch: report a failed watcher init as an error instead of a
crash
- #41185 bake: check for exceptions in the production build's module
loader hooks and helpers
- #41340 bake: skip the directory watch when the directory cannot be
opened
- #41617 Decide a directory watch event from the watchlist, not from the
resolver's cached listing *(crash fix only)*
- #42547 bake: re-arm the memory visualizer timer when it fires
- #42733 dev server: make a client script request wait for the bundle in
flight
- #42828 bake: serve routes from a router root outside the project root
instead of aborting or answering 404
- #42831 bake: resolve app.root and router roots through one checked
join
- #42836 bake: report route scan errors instead of aborting, and fail
bun build --app on them *(crash fix only)*
- #42840 dev server: map a router type's server entry point to the root
route of that type
- #42862 Bun.serve: return before a pending app.plugins setup() settles
*(crash fix only)*
- #42920 Do not create a mimalloc heap per FileSystemRouter, reload() or
:nth-child(An-B) selector
- #42934 dev server: register a client component without evaluating it
- #43329 dev server: check the route bundle index of a client script URL
before Index::init
- #44249 fs.watch: read each directory and close it before descending
- #44344 Windows: fix a watcher panic and lost events in a burst of file
changes, and a --hot that stops watching a deleted…
- #44744 dev server: answer a cached-file lookup only for a graph that
bundled the file
- #44746 dev server: keep an importer in its own graph when an import
fails or is deleted

**`Bun.serve`, sockets, HTTP, WebSocket, HTTP/2, QUIC, DNS** (28)

- #42667 Reland "usockets(windows): keep a closed poll alive until the
outer tick and libuv are done with it" (#39643)
- #33015 fix(windows): segfault in uv__wake_all_loops after system
resume *(crash fix only)*
- #35761 node:quic: detach lsquic ctx pointers before the finalize-order
sweep at worker VM teardown
- #37082 Bun.serve: terminate FIFO/pipe file responses at EOF
- #38024 dns: keep the c-ares uv_poll_t alive while its poll callback is
on the stack (Windows)
- #38636 serve: fix route use-after-free after reload() with
tls.serverName *(crash fix only)*
- #40888 server.fetch: copy a Headers argument instead of adopting the
wrapper's pointer
- #41337 Update lsquic to 4.9.4 and free unsent stateless resets on
destroy *(crash fix only)*
- #41384 usockets: hold a tick level for the whole of close_all
- #41412 Windows: wait for close completions when closing a worker's uv
loop
- #41516 node:http2: handle an empty byte range in respondWithFile and
respondWithFD
- #41521 udp: report every binaryType from the getter, reject a dgram
bind of the other family *(crash fix only)*
- #42188 net: do not assert a two-character host in SocketAddress.parse
- #42210 libuv(windows): keep a pipe's completed read counted until its
read callback returns
- #42334 fetch, Bun.serve: throw a RangeError for Headers that total 4
GiB or more *(crash fix only)*
- #43738 usockets: close a socket whose resume the kernel refuses from
the loop, not from the caller
- #44338 node:http: response trailers travel with the end call of the
response *(crash fix only)*
- #44433 bake: make the parked-request list non-owning and look up the
DevServer when a plugin load settles
- #44533 node:quic: capture the handshake while the conn is alive, set
the application at session creation
- #44734 Bun.serve: answer HEAD for an S3-backed Blob body without an S3
stat
- #44751 node:quic: close() waits only for opened streams, and lsquic
sends no GOAWAY before HTTP/3 starts *(crash fix only)*
- #44897 node:http2: throw instead of panic when the native
setNextStreamID() misses its argument
- #45076 node:http2: let close() and destroy() win over the refusal of a
request
- #45341 uws: AsyncSocket::write takes a size_t length, so res.end()
sends a body of 2 GiB or more whole
- #45522 node:http2: throw for an ALTSVC frame that is too long and for
a pushPromise id that is not a stream id
- #45676 node:quic: do not reset a stream lsquic has already finished
- #45822 node:quic: name a stream in queued session events by a
per-session key, not by its address
- #45858 Bun.serve WebSocket: a message that does not fit in memory
fails one connection, not the server *(crash fix only)*

**Streams, Blob, S3, files, `node:fs`** (28)

- #33845 io: propagate IoRequestLoop init failure instead of aborting
*(crash fix only)*
- #36365 prompt: drop debug_assert that rejects answers containing CR
- #37090 Deliver FIFO bodies whose writer connects after the reader
opens *(crash fix only)*
- #38039 node:fs: stop fs.copyFile(src, "") from segfaulting on Windows
- #38653 shell(cp): reject copying a directory into itself; walk cp
trees without recursion
- #39207 Convert scope-object receivers in the chaining functions and
inspect.custom fallbacks
- #39390 Blob deserialize: reject over-long paths, treat size >=
MAX_SIZE as unknown, make slice() non-panicking
- #39639 fetch: drop the upload and drain hop refs at VM teardown
*(crash fix only)*
- #40008 inspect hooks: copy user options with putDirectMayBeIndex
*(crash fix only)*
- #40462 Windows: FileSink.start({ path }) on a live writer: hand the
writer a libuv fd and close the old source *(crash fix only)*
- #41440 node:fs: pass the buffer to the read/readv/write/writev
callback on error
- #41584 Walk the timer pairing heap without recursion
- #41608 native-readable: accept a stream with no native handle
- #41710 JSSink write(): convert the chunk before resolving the native
sink *(crash fix only)*
- #42711 webstreams: bound the native recursion through a chain of tees
or text streams
- #43264 fetch: reject a file: URL whose path has an encoded NUL
- #43709 s3: fix double free of a multipart part's bytes on worker
terminate
- #43950 streams: link readers and writers last, reject their promises
as handled
- #44036 PipeReader: label a chunk Eof only when the reader is at its
end
- #44181 streams: throw instead of aborting when a direct stream's text
sink cannot take a string chunk
- #44195 fs: validate POSIX directory records in one parser, report a
malformed record as EIO *(crash fix only)*
- #44269 streams: join the string chunks of a text consumer with one
allocation
- #44490 watch(windows): report a failed child spawn as an error instead
of a panic *(crash fix only)*
- #44954 process.stdout/stderr with no FileSink: write synchronously,
reset after a failed write *(crash fix only)*
- #45004 streams: leave a stream alone when a consumer fails to lock it
- #45521 FileSink: throw ERR_ILLEGAL_CONSTRUCTOR from the constructor
that script reaches by writer.constructor
- #45738 s3: own the Blob store across the calls that run user JS
- #45975 node:stream: do not touch the web controller after the web side
is done

**Node-API, V8 API, `bun:ffi`, `process.dlopen`** (15)

- #36609 napi: implement uv_cwd on POSIX
- #37989 bun:ffi: stop cc() from turning non-numeric pointer arguments
into garbage pointers
- #38057 bun:ffi: make cc() reject non-numeric i64/u64 arguments instead
of passing garbage
- #38425 bun:ffi: throw on an empty cc() source array instead of
panicking
- #39652 napi: implement uv_async_t, uv_queue_work and uv_default_loop
on posix
- #39805 Share one handle scope implementation between Node-API and the
V8 API
- #39892 napi: implement uv_idle_t, uv_prepare_t, uv_check_t and
uv_timer_t on posix
- #40144 bun:ffi: return undefined for a NULL napi_value from cc() and
throw the scheduled napi exception
- #40773 bun:ffi: add the full byteOffset in read.*, do not truncate it
to int32
- #41704 napi: hand the thrown value to
napi_get_and_clear_last_exception after napi_run_script
- #42960 process.dlopen: run a V8 addon's init function after dlopen()
returns
- #43797 Fix debug assertion on an empty error message from a V8 addon
or SQLite *(crash fix only)*
- #43802 bun:ffi: throw a TypeError when a cc() symbol is called after
its library's close()
- #43940 napi: fail with ERR_BUFFER_TOO_LARGE instead of aborting above
the ArrayBuffer limit *(crash fix only)*
- #44921 bun:ffi: pad a short call to a cc() symbol with undefined

**`node:vm`, workers, process, timers** (19)

- #34623 node:vm: run DONT_CONTEXTIFY contexts directly against the real
global
- #32839 node:vm: reject invalid cachedData instead of crashing
- #36921 error printer: clear the pending exception when formatting a
non-Error uncaught value throws
- #37270 error printer: one render per error, [Circular] under the key
that closes the cycle
- #38740 bun:test: give each VM its own fake clock *(crash fix only)*
- #39864 Report a refused HTTP, bundle, IO or process waiter thread as
an error instead of a crash *(crash fix only)*
- #39992 process: deliver exceptions reported against a node:vm context
to uncaughtException
- #41654 node:vm: give each SourceTextModule request the import
attributes of the declaration that created it *(crash fix only)*
- #41739 Do not forward the inherited IPC channel to spawned scripts and
tools
- #41769 node:vm: stop compiling accepted cachedData, report each
cachedData decode to the GC *(crash fix only)*
- #42045 bun:test fake timers: never move the fake clock backwards
- #42308 process.execve: throw instead of aborting for a string past the
string limits
- #42734 node:vm: report cachedData of 2 GiB or more as rejected instead
of aborting
- #42843 process.dlopen: reject a filename of PATH_MAX or more before
dlopen()
- #43500 process: accept SIGSTKFLT, SIGPOLL and SIGPWR, and emit every
name of a signal number *(crash fix only)*
- #44486 worker: stop the start sequence when a handler it calls stops
the worker
- #44771 timers: allocate ids from one 64-bit counter that never wraps
- #44837 --hot: defer a reload during the preloads, and report a reload
that cannot start
- #44991 Fix a use-after-free in the VM ref-string intern for a string
over the length limit

**Shell, spawn, CLI, `bun test`, `bun install`** (31)

- #30642 Fail fast at startup when simdutf has no usable implementation
for this CPU
- #34223 Fix four crashes: HTMLRewriter disturbed body, S3 locked-stream
upload, ConnectionsList closed parser, shell brace… *(crash fix only)*
- #34884 Guard the console and test-runner formatters against native
stack overflow on deeply nested values *(crash fix only)*
- #36584 process.chdir: publish an immutable cwd slice so no thread sees
a torn cwd
- #37135 bun test --parallel: hold the JSC API lock while draining the
worker's final IPC backlog
- #37527 shell(mv): report ENAMETOOLONG instead of panicking when a
source name does not fit the path buffers
- #37528 cli: stop aborting on absolute script paths longer than 1024
bytes on Windows
- #38162 shell(cp): report ENAMETOOLONG instead of panicking on operands
longer than the path buffers
- #38205 shell(windows): report ENAMETOOLONG for operands that do not
fit the path buffer
- #39010 bun test: exit through the VM teardown path when --bail stops a
run
- #39104 bun test: report over-long coverage dir, JUnit outfile and
bunfig root instead of panicking *(crash fix only)*
- #39638 shell(cat): serve a second cat on the same stdin instead of
hanging or panicking
- #39641 usockets: report an out-of-descriptors event loop init as an
error, not a crash *(crash fix only)*
- #40181 shell: stop deeply nested if clauses from overflowing the
parser stack
- #40885 shell: throw instead of panicking when a ReadableStream is used
as a redirect
- #41155 ipc: send a queue item larger than 2 GiB in capped write
requests
- #42298 bun:test: print String objects with 16-bit storage correctly
- #42577 bun:test: root the return values toHaveReturnedWith collects
- #43606 shell(windows): report a failed pipe reader start through
on_reader_error instead of leaking the subprocess *(crash fix only)*
- #43838 node:cluster: read a worker's `ack` and `addressType` in the
primary only when they are int32
- #44172 node:cluster: refuse a descriptor of the wrong kind in the
primary *(crash fix only)*
- #44185 node:cluster: one handle for each descriptor that workers name
*(crash fix only)*
- #44491 bun test: run every callback when native code leaves an
exception pending *(crash fix only)*
- #44694 shell mv: refuse to copy a directory into itself on the
cross-device fallback
- #44752 shell: take the command-substitution capture and drop its NUL
bytes
- #44981 shell: reject NUL bytes in .cwd() and .env() at the native
setters
- #45206 ini: reject a source of 2 GiB or more in Parser::parse instead
of aborting on an int cast *(crash fix only)*
- #45348 bun test: fix a segfault in .not.toThrow(Class) when
Symbol.hasInstance accepts a thrown string, symbol or BigInt
- #45649 shell: replace the output counters in mkdir, cp, ls and touch
with the OutputTask queue
- #45792 bun test: SIGKILL a spawnSync child that is still running 500
ms after the test's timeout *(crash fix only)*
- #45910 create: own the remote-template response buffers instead of
parking them in the CLI arena

**Web APIs, Buffer, encoding, URL, crypto, zlib, SQLite, Redis and the
rest** (96)

- #29709 console: guard JSX/Proxy recursion in Bun.inspect (stack
overflow SIGSEGV)
- #30817 console.takeHeapSnapshot: clear prior snapshots before building
- #30956 spawnSync: make signal-forwarding register/unregister safe for
concurrent callers *(crash fix only)*
- #31505 node:zlib: reject invalid brotli flush values at validation
*(crash fix only)*
- #31735 node:path: fix win32 drive-relative resolve on non-Windows
hosts *(crash fix only)*
- #32085 Fix crash when RedisClient onclose/onconnect is set to a
non-callable
- #32240 Fix BroadcastChannel custom inspect crash with numeric option
keys
- #33181 Reject interior null bytes in Bun.mmap, Glob.scan, and
FileSystemRouter paths *(crash fix only)*
- #33752 node:crypto: validate EC JWK private scalar matches public
point in createPrivateKey
- #34976 spyOn: install and restore through one writer that throws when
the object refuses *(crash fix only)*
- #35562 structuredClone: purify NaN in deserialized Date timestamp so
getTime never returns a forged JSValue
- #35618 napi(windows): load addons that import node.exe without
win_delay_load_hook
- #35757 Coerce later arguments before capturing input buffers in
Bun.Transpiler and Bun.RedisClient
- #37252 Report UTF-16 to UTF-8 encode counts through size_t so exactly
2^32 written bytes doesn't wrap to 0
- #37338 node:module: build require.cache without user-writable globals
and propagate its exceptions *(crash fix only)*
- #37340 redis: accept unsubscribe acks that arrive outside subscriber
mode
- #37370 Error.appendStackTrace: make appending an error's trace to
itself a no-op
- #37443 node:crypto: fix null deref when worker.terminate() lands
during an EC JWK private key import
- #37448 jsc: check for exceptions before using a stored
constructEmptyArray result *(crash fix only)*
- #38009 MessagePort: fix a heap-use-after-free in contextDestroyed(),
release ref() when the last 'message' listener is rem… *(crash fix
only)*
- #38469 napi: settle or refuse async work queued during VM teardown
instead of taking a ticket
- #38708 Handle 16-bit module sources in the error preview, the
new-position fix-up and the REPL *(crash fix only)*
- #38821 process.env: make a failed env build throw instead of aborting
(Windows 0xC0000409 on Bun.$ / Bun.sql / process.env…
- #38871 process.env: coerce to string on every execution of an
assignment, not just the first
- #38877 cli: exit 128 + signo when bun cannot die from a re-raised
signal (bun as container PID 1)
- #38926 Clear the inherited signal mask at startup and exec children
with an empty one *(crash fix only)*
- #39382 Make a failed util.inspect load throw from custom inspect
functions instead of aborting
- #39481 Always create the error when a native error message exceeds the
string length limit
- #39651 performance: keep the user timing entry counts exact after
clearMarks(name) and clearMeasures(name)
- #39775 Turn seccomp SIGSYS traps into ENOSYS so the syscall fallbacks
run on Android
- #39968 process.dlopen: replay a non-context-aware V8 addon only while
no other live VM owns it
- #39975 watch: report a failed reload exec as an error instead of a
panic *(crash fix only)*
- #40346 Give Glob's native scan methods their own private names
- #40554 node:crypto: copy password and salt for async pbkdf2 and scrypt
- #40567 url: reject URL-encoded input over the WTF decode limit instead
of aborting
- #40577 url: throw a RangeError instead of aborting when
URLSearchParams or FormData outgrows its Vector
- #41073 Store array-index property names as indexed properties in
native object builders
- #41137 Write the sampling profiler report at exit from Bun, not JSC's
atexit hook
- #41365 webview: fail only the view when WebKit lacks
initWithDirectory:
- #41574 Decode a private copy of a JS buffer in the UTF-8 decoders
*(crash fix only)*
- #41652 console: read a BigInt depth option by value in console.dir
- #41749 Startup: reopen fd 0-2 as /dev/null only when the fd is closed
- #41819 Report an incoherent BUN_JSC_* option combination as a
configuration error, not a crash *(crash fix only)*
- #42158 webview: reject malformed Chrome replies instead of crashing
- #42179 shell: clamp a `> ${buf}` redirect to the target buffer's live
length
- #42187 node:crypto: throw ERR_OUT_OF_RANGE for >2 GiB buffer arguments
instead of aborting
- #42191 URLPattern: throw instead of aborting when a pattern string
passes the string limit
- #42192 Copy WebAssembly.Memory bytes for native borrows that outlive
the call *(crash fix only)*
- #42198 Make Bun.$, Bun.sql, Bun.postgres and Bun.SQL custom value
getters so reifying the Bun object passes exception chec…
- #42203 node:fs: fs.read into a WebAssembly.Memory view writes into the
block a grow freed
- #42214 Headers: throw a RangeError instead of aborting when the
set-cookie list cannot grow
- #42218 Headers: throw instead of aborting when a value passes the
string length limit
- #42220 URLPattern: throw instead of aborting when the token list
cannot grow
- #42225 Throw ERR_STRING_TOO_LONG from Bun.wrapAnsi instead of aborting
when the output passes the string length limit
- #42226 Throw instead of aborting when a MIME string does not fit in a
string *(crash fix only)*
- #42237 Bun.Cookie: throw instead of aborting when the Set-Cookie
string passes the string length limit
- #42249 Copy a shared input before libdeflate compresses it in
Bun.gzipSync and Bun.deflateSync
- #42253 bun test: walk nested describe scopes without native recursion
- #42259 Throw instead of aborting when a domainToASCII host passes the
string length limit
- #42310 Parse a private copy of a shared or resizable buffer in
Bun.Transpiler, Bun.markdown, Bun.YAML and Bun.TOML *(crash fix only)*
- #42312 YAML, JSON5, XML stringify: throw instead of aborting when the
output passes the string length limit
- #42318 Bound libdeflate's emit path so a racing input cannot overrun
the output
- #42338 inspector: check the type of process.argv in getModuleGraph
- #42364 node:perf_hooks: do not truncate the monitorEventLoopDelay
resolution to int32
- #42412 transpiler cache: reject an entry with no sourcemap section
- #42479 worker_threads: do not abort when
markAsUntransferable/markAsUncloneable gets a WebAssembly GC reference
- #42517 EventTarget: skip a listener object that has no realm
- #42518 fs.Stats: make the date accessors define the property like
Object.defineProperty *(crash fix only)*
- #42575 Stop natives from writing onto a foreign `this` with putDirect:
process.ppid, require.cache, StringDecoder, the nat… *(crash fix only)*
- #42631 JSStringView: pin the cell that owns the borrowed characters
- #42660 bun_core: read /dev/urandom when getrandom(2) answers ENOSYS or
EPERM
- #42780 node:crypto: treat a name too long to convert to UTF-8 as
unknown instead of aborting
- #42782 node:crypto: throw ERR_OUT_OF_RANGE for a passphrase larger
than INT_MAX bytes
- #42856 url: do not abort when a host is too long for the IDNA
conversion buffers
- #42868 sqlite, console, process: do not abort on a string too long to
convert to UTF-8 *(crash fix only)*
- #42941 Bun.sliceAnsi: throw instead of aborting when the result passes
the string length limit
- #43058 Bun.serve: fix crash and cross-request 500 when inspecting a
non-Response return value throws
- #43904 JSC bindings: build property keys from a BunString through
Bun::toIdentifier
- #44124 Bun.Image: decode WebP into a Bun-owned canvas and read ICCP
without the demuxer *(crash fix only)*
- #44190 Convert scope-object receivers before Buffer read*/write* and
vm.Script describe them
- #44211 Stop getsockname(out), useFakeTimers() and the stream source
pull() from writing onto a caller's object with putDirect
- #44295 bun test --coverage: append a final newline to a text that
lacks one *(crash fix only)*
- #44360 rust-argon2: return OutOfMemory instead of aborting when the
memory cost cannot be allocated
- #44421 node:zlib: free zstd's workers before the dictionary they read
- #44521 util.parseArgs: pick the default args start from a per-VM eval
flag, as Node v26 does *(crash fix only)*
- #44740 structured clone: tolerate a zero-sized shared
WebAssembly.Memory in computeMemoryCost()
- #44759 HTMLRewriter: park a suspended handler's token before the
output flush
- #44907 Builtins section format 2: an engine stamp says which buns
compile its modules
- #45188 Reject an oversized WebCrypto cipher output instead of aborting
- #45354 Throw for a `file:` URL whose path is not UTF-8 on Linux and
macOS, through one `fileSystemPath()` accessor *(crash fix only)*
- #45608 ipc: refuse an over-long message before the receive buffer
stores it
- #45624 webcrypto: write the key type into the X25519 structured-clone
record
- #45625 node:sqlite: refuse session.close() and Symbol.dispose inside a
SQLite callback
- #45653 glob: a group with `?` or a class matches when an alternative
takes 64 bytes or more
- #45820 Bun.file, S3Client.file and Bun.write no longer keep a buffer
path alive forever
- #45832 `bun check`: fix a panic on `export *` without a module
specifier, and a false error for one in parentheses

### Already fixed on `main`, or duplicates of a pull request above

Already fixed: #27323 #30401 #31011 #31206 #31566 #31626 #31695 #31702
#31945 #32773 #34154 #34697 #34744 #34964 #35655 #35816 #36020 #36181
#36296 #36342 #36581 #36602 #36807 #36818 #36857 #37172 #37235 #37239
#37267 #37420 #37731 #37914 #38113 #38119 #38509 #38514 #38540 #38975
#39410 #40749 #41163 #41171 #42108 #43085 #43230

Duplicates: #45654 #29986 #33378 #36895 #37070 #37639 #38014 #39021
#41266 #42250 #42951 #43238 #44259 #45335 #45565 #45726 #45965

Fixes #5019
Fixes #6106
Fixes #10690
Fixes #10886
Fixes #13566
Fixes #14745
Fixes #15551
Fixes #20454
Fixes #21310
Fixes #29145
Fixes #30454
Fixes #30613
Fixes #30766
Fixes #32103
Fixes #32142
Fixes #32183
Fixes #32212
Fixes #39060
Fixes #42296
Fixes #42931
Fixes #43671
Fixes #44201
Fixes #44735
Fixes #44783
Fixes #45198
Fixes #45327
Fixes #45491
Fixes #45721

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

This is Claude (an AI assistant) commenting on Jarred's behalf.

While putting #46021 together we checked this against main, and the crash it fixes no longer happens there. Closing. Please reopen it if that's wrong.

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