Repository navigation
Description
What version of Bun is running?
1.3.14 (0d9b296a), including the oven/bun:1.3.14 Docker image
What platform is your computer?
Linux only. Observed on GitHub Actions ubuntu-latest (x64) and reproduced in Docker linux/arm64 (Apple Silicon host). Not reproduced on native macOS — possibly because the failing syscall is epoll_ctl, which doesn't exist there, but that attribution is our guess.
What steps can reproduce the bug?
We hit this as an intermittent CI flake in a ~250-file bun test --isolate suite, and could reproduce it 8 out of 8 runs in a CPU-constrained container. We were unable to distill a standalone minimal repro (several targeted attempts — floods of stderr writes, node:assert imports across many isolate contexts, subprocess churn — never triggered it), so the recipe below uses the real suite at a pinned commit:
git clone https://github.com/gurenjs/guren && cd guren
git checkout --detach 9af07e910c297d9b4f6e096faee88def75ea55a7
docker run --rm --cpus=2 -v "$PWD":/src oven/bun:1.3.14 bash -c '
cp -r /src /work && cd /work
export APP_KEY=base64:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
bun install --frozen-lockfile && bun run build && bun run build:routes
# stderr must be a pipe (as under a CI runner); redirecting it straight to a
# regular file made the failure vanish in every run we tried
bun run test:bun > >(tee /tmp/out.log >/dev/null) 2> >(tee /tmp/err.log >/dev/null)
echo "test:bun exit: $?"
grep -c "EEXIST" /tmp/err.log
'bun run test:bun expands (at that commit) to a single invocation of bun test --isolate --preload scripts/test-cwd-guard.ts <one path per workspace package> — the expanded package list is printed on the [test] line at startup.
Real-world occurrences on GitHub Actions, all on 2026-08-12 and none related to the commit under test (each passed on rerun or on adjacent commits): job 94121054100 (a docs-only change), job 94139795319, job 94143320406.
What is the expected behavior?
Touching process.stderr for the first time inside an isolate context — including implicitly, via internal:util/colors when node:assert loads — should give back a working stream, and a test file whose module graph triggers that touch should load and run normally. If stream creation does fail, the failure should be observable/catchable from JS, and the summary should say which files died.
What do you see instead?
Intermittently, at a test-file boundary, an unhandled EEXIST from epoll_ctl while process.stderr is being created:
# Unhandled error between tests
error: EEXIST: file already exists, epoll_ctl
at new WriteStream (internal:fs/streams:244:58)
at refresh (internal:util/colors:18:39)
at internal:util/colors (internal:util/colors:24:16)
at internal:assert/assertion_error (internal:assert/assertion_error:2:187)
at loadAssertionError (node:assert:28:96)
at get (node:assert:70:30)
at node:assert (node:assert:588:29)
at <anonymous> (node_modules/redis-errors/lib/modern.js:3:7)
at <anonymous> (node_modules/redis-errors/index.js:3:88)
at <anonymous> (node_modules/ioredis/built/cluster/index.js:5:7)
at <anonymous> (node_modules/ioredis/built/Redis.js:6:7)
at <anonymous> (node_modules/ioredis/built/index.js:4:18)
What we can see from the JS side: under --isolate, every test file gets a fresh globals context and process.stderr is re-created lazily per context (verified: a property tagged onto process.stderr in one test file is gone in the next). Its constructor takes the fast path at internal:fs/streams:244, this[kWriteStreamFastPath] = fd ? Bun.file(fd).writer() : ..., and that construction is what dies. In our suite the first process.stderr touch in a context usually happens mid-module-load, because the first file whose import graph reaches ioredis evaluates ioredis → redis-errors → node:assert → internal:util/colors, whose refresh() calls shouldColorize(process.stderr).
Knock-on effects, all observed in the same runs:
- The CJS module that was loading (
ioredis) is left un-cached, so a later test file that imports it re-evaluates it and can crash the same way — single runs produced 4–6 of these reports, sometimes two in a row while loading the same test file's import graph. - After a failed creation,
process.stderrcan come backundefinedwithin that context, sodebug'suseColors()then dies withTypeError: undefined is not an object (evaluating 'process.stderr.fd')on the same load. - The test file whose load was interrupted reports
error: Cannot call describe() after the test run has completedfor each of itsdescribe()calls and is counted as failed.
Additional information
The failure is not observable from JS through the channels we tried. A try { process.stderr } catch {} around the first access never catches (the runner's unhandled-error report carries the construction stack, but no catch block ever sees it), and an 'error' listener attached synchronously to the returned stream never fires. And a preload cannot defuse it pre-emptively either: reading the property, Object.defineProperty(process, 'stderr', { value: replacement }), and delete process.stderr each reify the lazy property first — the native getter runs and constructs the stream as a side effect, which is the very operation that crashes. Each of these four preload variants was tried against the reproducing container and still failed, with the unhandled-error stack pointing at the preload's own line.
The workaround we verified: give the bun test process regular files instead of pipes for stdout/stderr and pump them back from a parent process. With that change the same container setup went 20/20 clean (vs. 8/8 failing before): gurenjs/guren#392
Possibly related (different symptom, same neighborhood — stdio stream creation failing on the event-loop registration syscall): #24158 (tty.WriteStream → EINVAL: invalid argument, kqueue on macOS).
Separate, smaller issue that makes this hard to triage from CI logs: when files die between tests like this, the summary prints N tests failed: but lists nothing under it — no (fail) line exists anywhere in the output. Naming the affected files there would help independently of the epoll bug. Happy to file that separately if preferred.
Activity
robobun commentedon Aug 13, 2026
✅ Reproduced: under
--isolateevery test file re-createsprocess.stdout/process.stderrover a fresh dup of the stdio fd plus an epoll registration, and the global swap never closed them. The EEXIST is a stale leaked registration colliding with a reused fd number over the same pipe.Fix in progress → #38008
Parikalp-Bhardwaj commentedon Aug 13, 2026
I traced this a bit further on current
mainand found a possible low-level cause insrc/io/posix_event_loop.rs.On Linux,
FilePoll::register_with_fd_impl()usesEPOLL_CTL_MODwhen the poll is already registered or hasNeedsRearm; otherwise it usesEPOLL_CTL_ADD.However, in
unregister_with_fd_impl(), whenNeedsRearmis set andforce_unregister == false, the function returns without issuingEPOLL_CTL_DEL, while clearing the poll registration flags.That looks like it could leave the userspace state and kernel epoll state out of sync:
A later registration of the same fd would then use
EPOLL_CTL_ADD, which could explain theEEXISTerror reported here.I also traced the stderr path roughly as:
I haven't confirmed yet that this is the exact teardown path hit by the reproducer, so I'm treating this as a root-cause hypothesis rather than a confirmed fix.
Would the intended invariant on Linux/Android be that a
FilePollbeing torn down must always remove its epoll registration, even whenNeedsRearmis set?If this direction looks correct, I'd be happy to add a focused regression test around the
NeedsRearm -> unregister -> re-registerpath and work on a small fix.test --isolate: end the outgoing file's process stdio sinks at the gl…
juliopolycarpo commentedon Aug 19, 2026
Independent confirmation from another codebase, plus one data point that contradicts the workaround in the issue body.
Bun 1.3.14, a 301-file / 3423-test suite, reached through
--parallel=Nrather than an explicit--isolate(--parallelimplies it). Samenew WriteStream (internal:fs/streams:244:58)frame, sameCannot call describe()/beforeEach()/afterEach() after the test run has completedon the file that was loading, same "a few failures plus a drop in the total" summary shape.ubuntu-latest, 4 vCPU,6.17.0-1022-azure--parallel=46.18.33.2,taskset -c 0-3--parallel=46.18.33.2,taskset -c 0-3--parallel=8, stdout+stderr to a regular file6.18.33.2,taskset -c 0-3--parallel=8, stdout+stderr into a pipeRegular files did not make it vanish here — they made it likelier (4/12 vs 2/8). So the files-instead-of-pipes workaround looks host- or suite-dependent rather than reliable; worth a caveat for anyone adopting it off this thread.
A second entry path into the same crash, which supports "any first stdio touch in a fresh context" over anything specific to
node:assert: our stack came in throughgoogle-logging-utils, which does__importStar(require("process"))at module scope. That copies every own property off theprocessmodule and so reifies the lazystdin/stdout/stderrgetters eagerly. It is reached transitively via@google/genai→google-auth-library. Removing that package from the module graph removes those frames and the aborts continue, with a barenew WriteStreamstack — so it is a messenger, not a cause.Reduction attempts that did not reproduce it, complementing the ones already listed: 200 files reading
process.stdout/process.stderrat module scope; 200 files doing the__importStarproperty copy above; 120 files importing@google/genai; 300 trivial files under a heavy real preload (config, DI registration, in-memory SQLite, migrations). All at--parallel=8. The trigger seems to need the real suite's per-file work.One runner detail that may matter to the fd/isolate bookkeeping: under
--parallel=Nthe main process also runs test files alongside the N-1 children, and files within any one process run strictly sequentially.docs(testing): point the unit-lane blocker at its upstream issue
juliopolycarpo commentedon Aug 19, 2026
Following up on my comment above with a more controlled comparison, because the obvious result is misleading.
Same 301-file / 3423-test suite, now in an
ubuntu:24.04container, each run pinned to an exclusive 4-core cpuset, with stdout/stderr on pipes. 234 runs across four Bun builds.I initially compared 1.3.14, current canary, and #38008, but that does not isolate the patch: canary is 2022 commits past the 1.3.14 tag and includes the Rust rewrite. I therefore added #38008's merge base,
23b18ddbc, so the relevant controlled comparison is:23b18ddbc→fd33b876dCanary no longer hits the abort, but still leaks
Reproduced #38008's regression-test idea against each build: 8 isolate files, each counting how many open fds point to the same pipe as fd 2.
1.3.14+0d9b296af4 6 8 10 12 14 16 181.4.0-canary.1+23b18ddbc(PR base)4 6 8 10 12 14 16 181.4.0-canary.1+32e87032b(canary)4 6 8 10 12 14 16 181.4.0-canary.1+fd33b876d(#38008)4 4 4 4 4 4 4 4So the per-isolate stdout/stderr leak is unchanged on current canary. Only #38008 removes it.
The suite-level result looks very different:
epoll_ctlaborts23b18ddbc32e87032bfd33b876dTaken alone, that table suggests newer Bun builds fixed the issue. The fd counts show otherwise: the collision stopped being reachable in this workload, while its precondition remained unchanged.
That seems worth calling out because a green run on current canary can look like a fix even though the underlying isolate stdio leak is still present.
It is also independent confirmation that #38008 removes the leak it targets.
The original failure signature is unchanged when it does occur:
Small follow-up on the regular-file workaround from my previous comment: it still does not improve this workload. At
--parallel=8, 2/4 runs were affected with stdout/stderr redirected to regular files versus 6/12 with pipes. I would treat that workaround as host/workload-specific rather than general.Separately, I observed four near-end-of-suite worker hangs on the unfixed builds and none in 85 completed #38008 runs. The sample is too small to establish a relationship, and the symptom is distinct from this issue, so I am keeping that out of this report unless I can reduce it further.
Environment: Ubuntu 24.04 userland, kernel
6.18.33.2-microsoft-standard-WSL2, 4-core cpuset per container. I would trust the build-to-build comparison here more than the absolute failure rates.--coveragewas also tested as a variable and did not materially change the abort rate.Canary stops reproducing the symptom, but does not fix the underlying cause; #38008 does.
perf(test): split the suite across CI jobs and report structured results
ci(frontend): rebuild the coverage lane on bun test (#912)
refactor(api): drop the dev frontend watcher
test --isolate: end the outgoing file's process stdio sinks at the gl…
io: leave the fd with the caller when a POSIX pipe writer fails to st…
test --isolate: end the outgoing file's process stdio sinks at the gl…
robobun commentedon Sep 18, 2026
The way the registration goes stale is now traced, at least for Bun's own CI.
A
process.stderrsink from an earlier isolated file is released by the GC whileBun.spawnSyncruns. During that call the VM's current event loop is the isolated spawnSync loop. So the sink'sEPOLL_CTL_DELgoes to the wrong epoll (ENOENT), and the entry stays in the main epoll after the dup is closed. The next dup of the same stdio fd that gets that number fails with EEXIST. In 147 runs of one CI test bucket, 118 of 118 stale entries came from this. Trace: #40078 (comment).#40078 fixes the wrong-epoll release. #38008 ends the per-file sinks before they can reach that window. If a suite that hits this error calls
spawnSyncorexecSyncin the test process (directly or in a dependency), the same source is likely there.test(ci): contain the Bun epoll_ctl flake that kills the packages lane
fix(db): stop the packages lane dying on a Bun isolate stdio leak
fix(mobile): theme.test's react-navigation stub exports what the app …
spawnSync: stop pointing the VM at the loop it waits on (oven-sh#44581)
perf(test): run API unit tests in parallel worker processes
perf(test): run API unit tests in parallel worker processes
perf(test): run API unit tests in parallel worker processes
perf(test): run API unit tests in parallel worker processes
perf(test): run API unit tests in parallel worker processes
perf(test): run API unit tests in parallel worker processes
perf(test): run API unit tests in parallel worker processes (#1406)
perf(test): run API unit tests in parallel worker processes (#1406)
Run the core, JOSE and Fetch contracts in Chromium, Firefox and WebKi…
build: upgrade Bun to 1.4.4 to fix the EEXIST epoll_ctl test flake (#369
chore: remove leftover Bun 1.3.13 references (#373)