child_process: fix assertion error in spawnSync

When ExitCallback was not called with an error such as ENOENT in
uv_spawn, the process handle still remains refed and needs to be closed.

Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>
archived-io.js-v0.10
Shigeki Ohtsu 2014-04-22 01:26:11 +09:00 committed by Timothy J Fontaine
parent 26a1b712ec
commit ab7a3d098d
2 changed files with 9 additions and 0 deletions

View File

@ -511,6 +511,11 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() {
if (uv_loop_ != NULL) { if (uv_loop_ != NULL) {
CloseStdioPipes(); CloseStdioPipes();
CloseKillTimer(); CloseKillTimer();
// Close the process handle when ExitCallback was not called.
uv_handle_t* uv_process_handle =
reinterpret_cast<uv_handle_t*>(&uv_process_);
if (!uv_is_closing(uv_process_handle))
uv_close(uv_process_handle, NULL);
// Give closing watchers a chance to finish closing and get their close // Give closing watchers a chance to finish closing and get their close
// callbacks called. // callbacks called.

View File

@ -39,6 +39,10 @@ console.log('sleep started');
var ret = spawnSync('sleep', ['1']); var ret = spawnSync('sleep', ['1']);
console.log('sleep exited'); console.log('sleep exited');
// Error test when command does not exist
var ret_err = spawnSync('command_does_not_exist');
assert.strictEqual(ret_err.error.code, 'ENOENT');
process.on('exit', function() { process.on('exit', function() {
assert.strictEqual(ret.status, 0); assert.strictEqual(ret.status, 0);