From ff432c8ef68b064940a809b70ad32238f6c29bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Reis?= Date: Tue, 16 Jul 2019 19:26:53 +0100 Subject: [PATCH] test,win: cleanup exec-timeout processes When CMD is used to launch a process and CMD is killed too quickly, the process can stay behind running in suspended state, never completing. This only happens in Windows Server 2008R2. Refs: https://github.com/nodejs/build/issues/1829 PR-URL: https://github.com/nodejs/node/pull/28723 Reviewed-By: Rich Trott Reviewed-By: Beth Griggs Reviewed-By: Colin Ihrig --- test/parallel/test-child-process-exec-timeout.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/parallel/test-child-process-exec-timeout.js b/test/parallel/test-child-process-exec-timeout.js index e08aff908522f2..343050e063c680 100644 --- a/test/parallel/test-child-process-exec-timeout.js +++ b/test/parallel/test-child-process-exec-timeout.js @@ -56,3 +56,19 @@ cp.exec(cmd, { timeout: 2 ** 30 }, common.mustCall((err, stdout, stderr) => { assert.strictEqual(stdout.trim(), 'child stdout'); assert.strictEqual(stderr.trim(), 'child stderr'); })); + +// Workaround for Windows Server 2008R2 +// When CMD is used to launch a process and CMD is killed too quickly, the +// process can stay behind running in suspended state, never completing. +if (common.isWindows) { + process.once('beforeExit', () => { + const basename = __filename.replace(/.*[/\\]/g, ''); + cp.execFileSync(`${process.env.SystemRoot}\\System32\\wbem\\WMIC.exe`, [ + 'process', + 'where', + `commandline like '%${basename}%child'`, + 'delete', + '/nointeractive' + ]); + }); +}