From ab7a3d098ddb13967014c723333c1df730da4940 Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Tue, 22 Apr 2014 01:26:11 +0900 Subject: [PATCH] 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 --- src/spawn_sync.cc | 5 +++++ test/simple/test-child-process-spawnsync.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 481d0eff09..29de6862d5 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -511,6 +511,11 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() { if (uv_loop_ != NULL) { CloseStdioPipes(); CloseKillTimer(); + // Close the process handle when ExitCallback was not called. + uv_handle_t* uv_process_handle = + reinterpret_cast(&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 // callbacks called. diff --git a/test/simple/test-child-process-spawnsync.js b/test/simple/test-child-process-spawnsync.js index f19200166a..e3304dc99c 100644 --- a/test/simple/test-child-process-spawnsync.js +++ b/test/simple/test-child-process-spawnsync.js @@ -39,6 +39,10 @@ console.log('sleep started'); var ret = spawnSync('sleep', ['1']); 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() { assert.strictEqual(ret.status, 0);