diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index a1db89e25a9fe3..b0b16649668158 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -4320,6 +4320,8 @@ pub fn NewFIFO(comptime EventLoop: JSC.EventLoopKind) type { } } + if (this.pending.state != .pending) return; + const read_result = this.read( this.buf, // On Linux, we end up calling ioctl() twice if we don't do this diff --git a/test/js/bun/io/bun-write.test.js b/test/js/bun/io/bun-write.test.js index 33c5c61d415c39..60534849e6c6db 100644 --- a/test/js/bun/io/bun-write.test.js +++ b/test/js/bun/io/bun-write.test.js @@ -479,3 +479,18 @@ describe("ENOENT", () => { }); }); }); + +it("timed output should work", async () => { + const producer_file = path.join(import.meta.dir, "timed-stderr-output.js"); + + const producer = Bun.spawn([bunExe(), "run", producer_file], { + stderr: "pipe", + }); + + let text = ""; + for await (const chunk of producer.stderr) { + text += [...chunk].map(x => String.fromCharCode(x)).join(""); + await new Promise(r => setTimeout(r, 1000)); + } + expect(text).toBe("0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n"); +}); diff --git a/test/js/bun/io/timed-stderr-output.js b/test/js/bun/io/timed-stderr-output.js new file mode 100644 index 00000000000000..42fc5becde3046 --- /dev/null +++ b/test/js/bun/io/timed-stderr-output.js @@ -0,0 +1,4 @@ +for (let i = 0; i <= 20; i++) { + await Bun.write(Bun.stderr, i + "\n"); + await new Promise(r => setTimeout(r, 100)); +}