From 43c9c201e34b6d6a4b75418ec4d20e147557dd80 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sat, 21 Nov 2026 06:46:51 -0800 Subject: [PATCH] The spawnSync overflow test no longer fails about once an hour on CI (GSTA-712) (#4613) The raw-Bun overflow test in test/spawn-sync.test.ts stops failing at random on CI: its child process now writes 32 KiB instead of 200,000 bytes. Why: the old write sat 13 KB under Linux's 212,992-byte socket send buffer. When it didn't fit, the child hit a broken pipe and exited 1, so the test saw status 1 instead of 0. Trunk flagged it 22 times in one day, and every time it passed on retry. Nothing to do: this changes tests only. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- .../flaky-spawn-overflow-fixture-fits-send-buffer.md | 1 + test/script-invocation.test.ts | 3 ++- test/spawn-sync.test.ts | 8 ++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 changelog.d/flaky-spawn-overflow-fixture-fits-send-buffer.md diff --git a/changelog.d/flaky-spawn-overflow-fixture-fits-send-buffer.md b/changelog.d/flaky-spawn-overflow-fixture-fits-send-buffer.md new file mode 100644 index 000000000..060ee488e --- /dev/null +++ b/changelog.d/flaky-spawn-overflow-fixture-fits-send-buffer.md @@ -0,0 +1 @@ +- **A flaky free test is fixed: the spawnSync overflow check no longer fails about once an hour on CI.** Its child process wrote 200,000 bytes, just under Linux's 212,992-byte socket send buffer. When the write didn't fit, the child hit a broken pipe and exited 1 instead of 0. The child now writes 32 KiB, which is still far past the test's 1 KiB output limit. This changes tests only. diff --git a/test/script-invocation.test.ts b/test/script-invocation.test.ts index 516b291d2..515909eae 100644 --- a/test/script-invocation.test.ts +++ b/test/script-invocation.test.ts @@ -230,7 +230,8 @@ describe('wtreeFingerprint', () => { describe('runScriptSync and runBashSync with output past maxBuffer (GST-3104)', () => { // A child that ignores SIGTERM outlives Bun's overflow kill and exits 0, so raw spawnSync would // report status 0 with ENOBUFS and cut-off stdout (GST-3086); these runners must report status null. - const OVERFLOW = "process.on('SIGTERM', () => {}); process.stdout.write('x'.repeat(200000)); setTimeout(() => {}, 300);"; + // The write fits the Unix socket send buffer, so the child really exits 0 (see test/spawn-sync.test.ts). + const OVERFLOW = "process.on('SIGTERM', () => {}); process.stdout.write('x'.repeat(32768)); setTimeout(() => {}, 300);"; const expectIncomplete = (r: { status: number | null; error?: Error; stderr: string }) => { expect(r.status).toBeNull(); expect((r.error as NodeJS.ErrnoException | undefined)?.code).toBe('ENOBUFS'); diff --git a/test/spawn-sync.test.ts b/test/spawn-sync.test.ts index 532217bc5..3bea07a15 100644 --- a/test/spawn-sync.test.ts +++ b/test/spawn-sync.test.ts @@ -3,7 +3,11 @@ * reads as a finished command. Bun can return status 0 together with error * ENOBUFS and cut-off stdout when the child exits before the overflow kill * lands (GSTA-618, seen on Bun 1.4.2 and 1.4.4). A child that ignores SIGTERM - * reproduces that every time, so these tests do not depend on timing. + * reproduces that every time, so these tests do not depend on timing, as long as + * its one write fits the Unix socket send buffer (212,992 bytes on Linux): a write + * that does not fit takes EPIPE when Bun closes its end, and the child exits 1 + * within about 10 ms. 200,000 bytes sat 13 KB under that buffer and flaked on CI + * (GSTA-712), so the child writes 32 KiB, still far past maxBuffer. */ import { describe, expect, test } from 'bun:test'; import { spawnSync as rawSpawnSync } from 'node:child_process'; @@ -26,7 +30,7 @@ function realGit(env: NodeJS.ProcessEnv = process.env): string { return Bun.which('git', { PATH: env.PATH }) || '/usr/bin/git'; } -const OVERFLOW = "process.on('SIGTERM', () => {}); process.stdout.write('x'.repeat(200000)); setTimeout(() => {}, 300);"; +const OVERFLOW = "process.on('SIGTERM', () => {}); process.stdout.write('x'.repeat(32768)); setTimeout(() => {}, 300);"; const overflowArgs = ['-e', OVERFLOW]; describe('spawnSync (lib/spawn-sync.ts)', () => {