From c57afe9bfeca34094994d7b31bfb9fa655d61beb Mon Sep 17 00:00:00 2001 From: cirospaciari Date: Mon, 4 Mar 2024 10:17:51 -0300 Subject: [PATCH] fix windows kill on subprocess/process --- src/bun.js/api/bun/process.zig | 5 ++++- src/bun.js/api/bun/subprocess.zig | 1 + src/bun.zig | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bun.js/api/bun/process.zig b/src/bun.js/api/bun/process.zig index 833715d273..ca103f53c5 100644 --- a/src/bun.js/api/bun/process.zig +++ b/src/bun.js/api/bun/process.zig @@ -494,7 +494,10 @@ pub const Process = struct { switch (this.poller) { .uv => |*handle| { if (handle.kill(signal).toError(.kill)) |err| { - return .{ .err = err }; + // if the process was already killed don't throw + if (err.errno != @intFromEnum(bun.C.E.SRCH)) { + return .{ .err = err }; + } } return .{ diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index 3aee00f958..6c7bfcede3 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -575,6 +575,7 @@ pub const Subprocess = struct { switch (this.tryKill(sig)) { .result => {}, .err => |err| { + // EINVAL or ENOSYS means the signal is not supported in the current platform (most likely unsupported on windows) globalThis.throwValue(err.toJSC(globalThis)); return .zero; }, diff --git a/src/bun.zig b/src/bun.zig index e1aabd2951..fe9e731fab 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -975,7 +975,9 @@ pub const SignalCode = enum(u8) { SIGSYS = 31, _, - pub const default = if (Environment.isWindows) 1 else @intFromEnum(SignalCode.SIGTERM); + // The `subprocess.kill()` method sends a signal to the child process. If no + // argument is given, the process will be sent the 'SIGTERM' signal. + pub const default = @intFromEnum(SignalCode.SIGTERM); pub const Map = ComptimeEnumMap(SignalCode); pub fn name(value: SignalCode) ?[]const u8 { if (@intFromEnum(value) <= @intFromEnum(SignalCode.SIGSYS)) {