diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index db03d48428..02db4c98a7 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -862,7 +862,7 @@ pub const Subprocess = struct { switch (this.state) { .pending => { - const stream = JSC.WebCore.ReadableStream.fromPipe(globalObject, &this.reader); + const stream = JSC.WebCore.ReadableStream.fromPipe(globalObject, this, &this.reader); this.state = .{ .done = &.{} }; return stream; }, diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index 2375d4a6f2..705a6ae56d 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -360,6 +360,7 @@ pub const ReadableStream = struct { pub fn fromPipe( globalThis: *JSGlobalObject, + parent: anytype, buffered_reader: anytype, ) JSC.JSValue { JSC.markBinding(@src()); @@ -371,6 +372,11 @@ pub const ReadableStream = struct { }); source.context.reader.from(buffered_reader, &source.context); + if (comptime Environment.isPosix) { + source.context.fd = parent.fd; + parent.fd = bun.invalid_fd; + } + return source.toJS(globalThis); } diff --git a/src/io/PipeReader.zig b/src/io/PipeReader.zig index 5a8e72b1f3..7cc2c49829 100644 --- a/src/io/PipeReader.zig +++ b/src/io/PipeReader.zig @@ -544,7 +544,8 @@ const PosixBufferedReader = struct { pub fn registerPoll(this: *PosixBufferedReader) void { const poll = this.handle.getPoll() orelse brk: { if (this.handle == .fd and this.pollable) { - break :brk Async.FilePoll.init(this.eventLoop(), this.getFd(), .{}, @This(), this); + this.handle = .{ .poll = Async.FilePoll.init(this.eventLoop(), this.getFd(), .{}, @This(), this) }; + break :brk this.handle.poll; } return;