diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index 917b303adf1522..b0ad31e4cb2b1c 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -723,7 +723,7 @@ pub const Subprocess = struct { IPClog("Subprocess#doSend", .{}); const ipc_data = &(this.ipc_data orelse { if (this.hasExited()) { - return global.throw("Subprocess.send() cannot be used after the process has exited.", .{}); + return global.ERR_IPC_CHANNEL_CLOSED("Subprocess.send() cannot be used after the process has exited.", .{}).throw(); } else { return global.throw("Subprocess.send() can only be used if an IPC channel is open.", .{}); } diff --git a/test/js/node/test/parallel/test-child-process-send-after-close.js b/test/js/node/test/parallel/test-child-process-send-after-close.js new file mode 100644 index 00000000000000..01e4d34d1f7bd6 --- /dev/null +++ b/test/js/node/test/parallel/test-child-process-send-after-close.js @@ -0,0 +1,31 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const cp = require('child_process'); +const fixtures = require('../common/fixtures'); + +const fixture = fixtures.path('empty.js'); +const child = cp.fork(fixture); + +child.on('close', common.mustCall((code, signal) => { + assert.strictEqual(code, 0); + assert.strictEqual(signal, null); + + const testError = common.expectsError({ + name: 'Error', + // message: 'Channel closed', + code: 'ERR_IPC_CHANNEL_CLOSED' + }, 2); + + child.on('error', testError); + + { + const result = child.send('ping'); + assert.strictEqual(result, false); + } + + { + const result = child.send('pong', testError); + assert.strictEqual(result, false); + } +}));