From da12b10005e9ab4e52feb4101ac0ba373d290ad6 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 28 May 2016 11:28:01 +0200 Subject: [PATCH] test: work around debugger not killing inferior On UNIX platforms, the debugger doesn't reliably kill the inferior when killed by a signal. Work around that by spawning the debugger in its own process group and killing the process group instead of just the debugger process. This is a hack to get the continuous integration back to green, it doesn't address the underlying issue, which is that the debugger shouldn't leave stray processes behind. Fixes: https://github.com/nodejs/node/issues/7034 PR-URL: https://github.com/nodejs/node/pull/7037 Refs: https://github.com/nodejs/node/pull/3470 Reviewed-By: Colin Ihrig --- test/parallel/test-debug-port-numbers.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-debug-port-numbers.js b/test/parallel/test-debug-port-numbers.js index e21cb72f0a0622..c7bf1da5f64849 100644 --- a/test/parallel/test-debug-port-numbers.js +++ b/test/parallel/test-debug-port-numbers.js @@ -5,11 +5,17 @@ const assert = require('assert'); const path = require('path'); const spawn = require('child_process').spawn; +// FIXME(bnoordhuis) On UNIX platforms, the debugger doesn't reliably kill +// the inferior when killed by a signal. Work around that by spawning +// the debugger in its own process group and killing the process group +// instead of just the debugger process. +const detached = !common.isWindows; + const children = []; for (let i = 0; i < 4; i += 1) { const port = common.PORT + i; const args = [`--debug-port=${port}`, '--interactive', 'debug', __filename]; - const child = spawn(process.execPath, args, { stdio: 'pipe' }); + const child = spawn(process.execPath, args, { detached, stdio: 'pipe' }); child.test = { port: port, stdout: '' }; child.stdout.setEncoding('utf8'); child.stdout.on('data', function(s) { child.test.stdout += s; update(); }); @@ -28,7 +34,18 @@ function update() { if (ready === children.length) for (const child of children) - child.kill(); + kill(child); +} + +function kill(child) { + if (!detached) + return child.kill(); + + try { + process.kill(-child.pid); // Kill process group. + } catch (e) { + assert.strictEqual(e.code, 'ESRCH'); // Already gone. + } } process.on('exit', function() {