Skip to content

Commit

Permalink
test,win: cleanup exec-timeout processes
Browse files Browse the repository at this point in the history
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: nodejs/build#1829

PR-URL: #28723
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
joaocgreis authored and BethGriggs committed Sep 19, 2019
1 parent 1a5dc6a commit 92a2f8b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/parallel/test-child-process-exec-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]);
});
}

0 comments on commit 92a2f8b

Please sign in to comment.