From 167c8e4644d694fff7d1d2ce3d7419fb97104387 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 23 Feb 2024 02:12:31 +0100 Subject: [PATCH 1/3] test: fix test-child-process-fork-net The child processes are supposed to get 4 messages (2 ends, 2 writes). Previously the mustCall() wrapping the message listener attempts to match exactly 1 invocation which is bound to fail but could be swallowed if the child happens to be killed before the exit event is fired for the mustCall() check to work. In the CI, on some machines the kill() could happen after the child process finishes with the mustCall() check, resulting in EPERM errors in kill(). This patch fixes the mustCall() checks (updating the expected invocation count to 4) and swallow the errors when kill() fails, which should be fine because they are only there for cleanup. --- test/parallel/test-child-process-fork-net.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-child-process-fork-net.js b/test/parallel/test-child-process-fork-net.js index 0760ca44adc3c7..84ec8a3cadae08 100644 --- a/test/parallel/test-child-process-fork-net.js +++ b/test/parallel/test-child-process-fork-net.js @@ -19,6 +19,9 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. +// This tests that a socket sent to the forked process works. +// See https://github.com/nodejs/node/commit/dceebbfa + 'use strict'; const { mustCall, @@ -65,7 +68,7 @@ if (process.argv[2] === 'child') { socket.on('finish', mustCall(() => { debug(`[${id}] socket finished ${m}`); })); - })); + }, 4)); process.on('message', mustCall((m) => { if (m !== 'close') return; @@ -74,7 +77,7 @@ if (process.argv[2] === 'child') { debug(`[${id}] ending ${i}/${needEnd.length}`); endMe.end('end'); }); - })); + }, 4)); process.on('disconnect', mustCall(() => { debug(`[${id}] process disconnect, ending`); @@ -146,9 +149,14 @@ if (process.argv[2] === 'child') { server.on('close', mustCall(function() { closeEmitted = true; - child1.kill(); - child2.kill(); - child3.kill(); + // Clean up child processes. + try { + child1.kill(); + child2.kill(); + child3.kill(); + } catch (e) { + debug('child process already terminated'); + } })); server.listen(0, '127.0.0.1'); From 5b5cdb961acbc8be635716d155b23dc102e75ef0 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 23 Feb 2024 02:27:53 +0100 Subject: [PATCH 2/3] fixup! test: fix test-child-process-fork-net --- test/parallel/test-child-process-fork-net.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-child-process-fork-net.js b/test/parallel/test-child-process-fork-net.js index 84ec8a3cadae08..c33c8b785ad13d 100644 --- a/test/parallel/test-child-process-fork-net.js +++ b/test/parallel/test-child-process-fork-net.js @@ -154,7 +154,7 @@ if (process.argv[2] === 'child') { child1.kill(); child2.kill(); child3.kill(); - } catch (e) { + } catch { debug('child process already terminated'); } })); From 17b9569469bfcc821a60cd44e563d43e8440873c Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 23 Feb 2024 19:38:26 +0100 Subject: [PATCH 3/3] fixup! fixup! test: fix test-child-process-fork-net --- test/parallel/test-child-process-fork-net.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/parallel/test-child-process-fork-net.js b/test/parallel/test-child-process-fork-net.js index c33c8b785ad13d..bf19a2bdd152d9 100644 --- a/test/parallel/test-child-process-fork-net.js +++ b/test/parallel/test-child-process-fork-net.js @@ -152,7 +152,15 @@ if (process.argv[2] === 'child') { // Clean up child processes. try { child1.kill(); + } catch { + debug('child process already terminated'); + } + try { child2.kill(); + } catch { + debug('child process already terminated'); + } + try { child3.kill(); } catch { debug('child process already terminated');