Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion test/js/bun/spawn/spawn-streaming-stdin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ test("spawn can write to stdin multiple chunks", async () => {
remaining -= concurrency;
}

const newMaxFD = getMaxFD();
// Pipe fds are closed on a background thread after their streams finish, so
// the last batch's closes may still be in flight here; wait for them to land.
let newMaxFD = getMaxFD();
for (let i = 0; i < 100 && newMaxFD !== maxFD; i++) {
await Bun.sleep(10);
newMaxFD = getMaxFD();
}
Comment thread
robobun marked this conversation as resolved.
Resolved

// assert we didn't leak any file descriptors
expect(newMaxFD).toBe(maxFD);
Expand Down
21 changes: 19 additions & 2 deletions test/js/bun/spawn/spawn-streaming-stdout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,28 @@ test("spawn can read from stdout multiple chunks", async () => {
await Promise.all(promises);
i += concurrency;
if (maxFD === -1) {
// Pipe fds are closed on a background thread after their streams finish,
// so the first batch's closes may still be in flight here; poll until the
// count settles so the baseline isn't inflated.
maxFD = getMaxFD();
for (let j = 0; j < 100; j++) {
await Bun.sleep(10);
const settled = getMaxFD();
if (settled === maxFD) break;
maxFD = settled;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}
const newMaxFD = getMaxFD();
expect(newMaxFD).toBe(maxFD);
// Same race for the last batch's closes; wait for the fd count to drop back
// to the baseline before asserting. The settled baseline can still come out
// slightly high (it has no pre-spawn ground truth; #6724 moved it after the
// first batch on purpose), so ending below it is fine; only above is a leak.
let newMaxFD = getMaxFD();
for (let i = 0; i < 100 && newMaxFD > maxFD; i++) {
await Bun.sleep(10);
newMaxFD = getMaxFD();
}
expect(newMaxFD).toBeLessThanOrEqual(maxFD);
clearInterval(interval);
await expectMaxObjectTypeCount(expect, "ReadableStream", 10);
await expectMaxObjectTypeCount(expect, "ReadableStreamDefaultReader", 10);
Expand Down