From 4bbcc39d2f46d0fd9873732f25e3cedd460a408a Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:10:26 -0700 Subject: [PATCH] pipe.signal.ptr == subprocess.stdin, not subprocess --- src/bun.js/api/bun/subprocess.zig | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index ea7f9ec808..7ecf3bdde6 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -1248,6 +1248,17 @@ pub const Subprocess = struct { } } + fn clearSignal(this: *Writable, subprocess: *const Subprocess, signal: *JSC.WebCore.Signal) void { + if (@intFromPtr(signal.ptr) == @intFromPtr(this)) { + signal.clear(); + } + if (comptime Environment.allow_assert) { + // signal should only be assigned to the Writable + // not the Subprocess + std.debug.assert(signal.ptr != @as(*anyopaque, @ptrCast(@constCast(subprocess)))); + } + } + pub fn toJS(this: *Writable, globalThis: *JSC.JSGlobalObject, subprocess: *Subprocess) JSValue { return switch (this.*) { .fd => |fd| fd.toJS(globalThis), @@ -1261,9 +1272,9 @@ pub const Subprocess = struct { } else { subprocess.flags.has_stdin_destructor_called = false; subprocess.weak_file_sink_stdin_ptr = pipe; - if (@intFromPtr(pipe.signal.ptr) == @intFromPtr(subprocess)) { - pipe.signal.clear(); - } + + clearSignal(this, subprocess, &pipe.signal); + return pipe.toJSWithDestructor( globalThis, JSC.WebCore.SinkDestructor.Ptr.init(subprocess), @@ -1283,9 +1294,7 @@ pub const Subprocess = struct { return switch (this.*) { .pipe => |pipe| { - if (pipe.signal.ptr == @as(*anyopaque, @ptrCast(this))) { - pipe.signal.clear(); - } + clearSignal(this, subprocess, &pipe.signal); pipe.deref();