From aeef1ca5d2791ea9fa29c5627b1a9b445c9bfbc0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 5 Jun 2025 23:06:54 +0000 Subject: [PATCH] Add test for child process send return value and fix header extraction --- bun | 1 + src/bun.js/bindings/webcore/HTTPHeaderMap.cpp | 2 +- ...test-child-process-send-returns-boolean.js | 58 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 160000 bun create mode 100644 test/js/node/test/parallel/test-child-process-send-returns-boolean.js diff --git a/bun b/bun new file mode 160000 index 0000000000..f62940bbda --- /dev/null +++ b/bun @@ -0,0 +1 @@ +Subproject commit f62940bbdaa7df8738093d78ca490567caf052d2 diff --git a/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp b/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp index 9b95c823de..35bb6151d9 100644 --- a/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp +++ b/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp @@ -40,7 +40,7 @@ static StringView extractCookieName(const StringView& cookie) { auto nameEnd = cookie.find('='); if (nameEnd == notFound) - return String(); + return StringView(); return cookie.substring(0, nameEnd); } diff --git a/test/js/node/test/parallel/test-child-process-send-returns-boolean.js b/test/js/node/test/parallel/test-child-process-send-returns-boolean.js new file mode 100644 index 0000000000..8c3ef46438 --- /dev/null +++ b/test/js/node/test/parallel/test-child-process-send-returns-boolean.js @@ -0,0 +1,58 @@ +'use strict'; +const common = require('../common'); + +// subprocess.send() will return false if the channel has closed or when the +// backlog of unsent messages exceeds a threshold that makes it unwise to send +// more. Otherwise, the method returns true. + +const assert = require('assert'); +const net = require('net'); +const { fork, spawn } = require('child_process'); +const fixtures = require('../common/fixtures'); + +// Just a script that stays alive (does not listen to `process.on('message')`). +const subScript = fixtures.path('child-process-persistent.js'); + +{ + // Test `send` return value on `fork` that opens and IPC by default. + const n = fork(subScript); + // `subprocess.send` should always return `true` for the first send. + const rv = n.send({ h: 'w' }, assert.ifError); + assert.strictEqual(rv, true); + n.kill('SIGKILL'); +} + +{ + // Test `send` return value on `spawn` and saturate backlog with handles. + // Call `spawn` with options that open an IPC channel. + const spawnOptions = { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }; + const s = spawn(process.execPath, [subScript], spawnOptions); + + const server = net.createServer(common.mustNotCall()).listen(0, () => { + const handle = server._handle; + + // Sending a handle and not giving the tickQueue time to acknowledge should + // create the internal backlog, but leave it empty. + const rv1 = s.send('one', handle, (err) => { if (err) assert.fail(err); }); + assert.strictEqual(rv1, true); + // Since the first `send` included a handle (should be unacknowledged), + // we can safely queue up only one more message. + const rv2 = s.send('two', (err) => { if (err) assert.fail(err); }); + assert.strictEqual(rv2, true); + // The backlog should now be indicate to backoff. + const rv3 = s.send('three', (err) => { if (err) assert.fail(err); }); + assert.strictEqual(rv3, false); + const rv4 = s.send('four', (err) => { + if (err) assert.fail(err); + // `send` queue should have been drained. + const rv5 = s.send('5', handle, (err) => { if (err) assert.fail(err); }); + assert.strictEqual(rv5, true); + + // End test and cleanup. + s.kill(); + handle.close(); + server.close(); + }); + assert.strictEqual(rv4, false); + }); +}