Skip to content

Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA

TypeScript

The spawnSync overflow test no longer fails about once an hour on CI (GSTA-712) (#4613)

Garry Tan43c9c201e34b
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)', () => {