Skip to content

fix(test/apps): the driver bounds every wait on a child's exit and retries a spawn that fails with EBADF before the child runs (#997) - #1013

Merged
davideast merged 1 commit into
mainfrom
fix/app-driver-spawn-flake
Oct 16, 2026
Merged

davideast merged 1 commit into
mainfrom
fix/app-driver-spawn-flake

Conversation

@davideast

Copy link
Copy Markdown
Owner

The app scenario driver now gives up on a child that never closes after SIGKILL, and starts a child once more when Bun's spawn fails with EBADF before the child wrote anything.

// test/apps/driver.test.ts: a child whose stdout pipe a process outside its group holds open
const child = new AppProcess('pipe holder', 'sh',
  ['-c', `setsid sh -c 'echo $$; exec sleep 30' & exec sleep 30`], '.', { PATH: process.env.PATH });
await child.waitForLog(/^(\d+)$/m);
await child.stop({ termMs: 200, killMs: 200 });   // before: awaited `exited` forever
child.running;   // false
await child.exited;   // null
child.output;    // "...[driver] pipe holder did not close within 0.2s of SIGKILL; the driver records it as gone"

stop() waits at most 5 seconds after SIGKILL

Bun's node:child_process emits close only after the child's stdout and stderr close, and AppProcess.exited settled only on close or error. A process the group kill does not reach that holds those pipes keeps close from arriving, so stop() awaited exited with no limit and the job ran to its 30-minute timeout (#995's first attempt). stop() now waits termMs after SIGTERM and killMs after SIGKILL (5 s each by default), then records the process as gone, writes that in its log, and settles exited with null. Every other wait on a child in the driver was already bounded or goes through stop(): serverScript races exited against its timeout and then calls stop(), devServer reads exited only once the process is no longer running, and teardown calls stop() on every process.

A SIGTERM that fails because the group is already gone used to return at once with the process still marked running; it now goes through the same bounded wait.

A spawn that fails with EBADF before any output is started once more

[driver] could not start node: EBADF: bad file descriptor, epoll_ctl; the child wrote no output, so the driver starts it once more

Only EBADF, only on the first attempt, and only when the child wrote no output. A second EBADF, any other spawn error, or an EBADF after output fails the step as before. If the failed child got a pid, its group gets SIGKILL before the new spawn, and events from the abandoned child are ignored.

Risk

A real hang in a scenario's process now ends 10 seconds after stop() begins instead of at the job timeout, with the note above in that process's log. A process recorded as gone may still be alive; the run's temporary directory removal and the runner exiting are what clean up after it, as before.

No Bun upgrade here. No Bun issue names this EBADF ... epoll_ctl spawn failure on Linux (details below).

Implementation notes

Runtime path: none beyond the test driver itself. The change is in test/apps/driver.ts, which every app scenario uses, so the scenario runs below are its integration evidence. The slow scenarios use stop() and pause/resume, so this PR has the ci-slow-scenarios label.

Files: test/apps/driver.ts, test/apps/driver.test.ts (new), test/apps/README.md, .github/workflows/build.yml (the App scenarios job's unit step runs driver.test.ts beside selection.test.ts).

AppProcess takes an optional spawner as its last constructor argument (default spawn from node:child_process), which the retry tests use for stand-in children without a pid. The stop() tests use real processes.

Local verification, Bun 1.3.11, WSL2:

  • bun test test/apps/selection.test.ts test/apps/driver.test.ts: 16 pass, 0 fail
  • bun test/apps/run.ts --build --skip-slow: 12 apps passed (193.2s)
  • bun test/apps/run.ts --skip-slow: 12 apps passed (140.1s)
  • bun test/apps/run.ts --only-slow: 2 apps passed (143.8s)
  • No log in any run had a retry or a recorded-as-gone note.

Bun findings (we pin 1.3.11; latest is 1.4.3):

…tries a spawn that fails with EBADF before the child runs (#997)

AppProcess.stop() now waits at most 5s after SIGKILL. A child that has
still not closed is recorded as gone with a note in its log, and its
`exited` settles, so serverScript's timeout path and the run's teardown
end instead of running to the job timeout. Bun's child_process emits
`close` only after the child's pipes close, so a process outside the
group that holds them keeps `close` from ever arriving; the new unit
test reproduces that with a setsid'd sleep.

A spawn that fails with EBADF before the child wrote any output is
started once more, with a line in the process log. Any other spawn
error, a second EBADF, or an EBADF after output fails as before.

Closes #997
@davideast davideast added the ci-slow-scenarios Run the slow app scenarios (timer-bound) on this PR label Oct 16, 2026
@davideast
davideast merged commit 4e6222d into main Oct 16, 2026
21 checks passed
@davideast
davideast deleted the fix/app-driver-spawn-flake branch November 21, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-slow-scenarios Run the slow app scenarios (timer-bound) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant