child_process: fix assertion error in spawnSync
authorShigeki Ohtsu <ohtsu@iij.ad.jp>
Mon, 21 Apr 2014 16:26:11 +0000 (01:26 +0900)
committerTimothy J Fontaine <tjfontaine@gmail.com>
Wed, 30 Apr 2014 16:02:18 +0000 (09:02 -0700)
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>
src/spawn_sync.cc
test/simple/test-child-process-spawnsync.js

index 481d0ef..29de686 100644 (file)
@@ -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_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
     // callbacks called.
index f192001..e3304dc 100644 (file)
@@ -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);