{"action":"created","issue":{"url":"https://api.github.com/repos/heroku/heroku-pipelines/issues/19","labels_url":"https://api.github.com/repos/heroku/heroku-pipelines/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/heroku/heroku-pipelines/issues/19/comments","events_url":"https://api.github.com/repos/heroku/heroku-pipelines/issues/19/events","html_url":"https://github.com/heroku/heroku-pipelines/issues/19","id":125159371,"number":19,"title":"pipelines:add fails to exit when called from another node process","user":{"login":"redbugz","id":63466,"avatar_url":"https://avatars.githubusercontent.com/u/63466?v=3","gravatar_id":"","url":"https://api.github.com/users/redbugz","html_url":"https://github.com/redbugz","followers_url":"https://api.github.com/users/redbugz/followers","following_url":"https://api.github.com/users/redbugz/following{/other_user}","gists_url":"https://api.github.com/users/redbugz/gists{/gist_id}","starred_url":"https://api.github.com/users/redbugz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/redbugz/subscriptions","organizations_url":"https://api.github.com/users/redbugz/orgs","repos_url":"https://api.github.com/users/redbugz/repos","events_url":"https://api.github.com/users/redbugz/events{/privacy}","received_events_url":"https://api.github.com/users/redbugz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-06T11:24:00Z","updated_at":"2016-01-25T23:10:31Z","closed_at":null,"body":"We are executing heroku commands with Node and when we call `heroku pipelines:add` if the command succeeds, the child process never exits which hangs the parent process.\r\n\r\nWe were using execFile, but I switched to spawn so we could watch the output. If the command is run directly from the terminal, it works fine. Since pipelines are not [supported in the API](https://github.com/heroku/node-heroku-client) yet, exec-ing the toolbelt is the easiest way to implement this that I know. If we should try to require this module and use it directly instead, we could try that I guess.\r\n\r\nI tried this with Node 0.10, 0.12, and 4.2 with the same result. We can't use 5 yet, so I haven't tried that. We are transitioning off of 0.10 over the next few months, but we still need this work until then.\r\n\r\nWhat our code is doing (with dummy names for pipeline and app instead of the variables we pass):\r\n```\r\n      var execFile = require('child_process').execFile,\r\n        child;\r\n\r\n      console.log('calling heroku pipelines ...');\r\n      child = execFile('heroku', ['pipelines:add', 'my-pipeline', '--stage', 'development', '--app', 'my-app-name'],\r\n        function (error, stdout, stderr) {\r\n          if (error !== null) {\r\n            console.log('$execFile error: ' + error);\r\n          }\r\n          console.log('$stdout: ' + stdout);\r\n          console.log('$stderr: ' + stderr);\r\n        });\r\n```\r\nWith the resulting output:\r\n```\r\ncalling heroku pipelines ...\r\n```\r\nbut the callback is never called, the process doesn't exit, and the `ps` command still shows the heroku command running.\r\n\r\nWhen using spawn to watch the output more carefully:\r\n```\r\n      var spawn = require('child_process').spawn,\r\n        ls    = spawn('heroku', ['pipelines:add', 'my-pipeline', '--stage', 'development', '--app', 'my-app-name']);\r\n\r\n      ls.stdout.on('data', function (data) {\r\n        console.log('$stdout: ' + data);\r\n      });\r\n\r\n      ls.stderr.on('data', function (data) {\r\n        console.log('$stderr: ' + data);\r\n        //if (/^done/.test(data)) {\r\n        //  console.log('killing');\r\n        //  ls.kill('SIGQUIT');\r\n        //}\r\n      });\r\n\r\n      ls.on('close', function (code) {\r\n        console.log('$child process exited with code ' + code);\r\n      });\r\n```\r\nWith output:\r\n```\r\n$stdout: \r\n$stderr: Adding my-app-name to my-pipeline pipeline as development... \r\n$stderr: done\r\n\r\n```\r\nBut we never get the 'close' event, and the process hangs.\r\n\r\nRunning the command directly in the terminal works fine:\r\n```\r\n$ heroku pipelines:add my-pipeline --stage development --app my-app-name\r\nAdding my-app-name to my-pipeline pipeline as development... done\r\n$ echo $?\r\n0\r\n$\r\n```\r\n\r\nUsing the regex check for done in the stderr stream in the spawn example and force killing the process, or using the `{timeout: 3000}` option in execFile also work around the issue, but aren't very tidy."},"comment":{"url":"https://api.github.com/repos/heroku/heroku-pipelines/issues/comments/174722687","html_url":"https://github.com/heroku/heroku-pipelines/issues/19#issuecomment-174722687","issue_url":"https://api.github.com/repos/heroku/heroku-pipelines/issues/19","id":174722687,"user":{"login":"dickeyxxx","id":216188,"avatar_url":"https://avatars.githubusercontent.com/u/216188?v=3","gravatar_id":"","url":"https://api.github.com/users/dickeyxxx","html_url":"https://github.com/dickeyxxx","followers_url":"https://api.github.com/users/dickeyxxx/followers","following_url":"https://api.github.com/users/dickeyxxx/following{/other_user}","gists_url":"https://api.github.com/users/dickeyxxx/gists{/gist_id}","starred_url":"https://api.github.com/users/dickeyxxx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dickeyxxx/subscriptions","organizations_url":"https://api.github.com/users/dickeyxxx/orgs","repos_url":"https://api.github.com/users/dickeyxxx/repos","events_url":"https://api.github.com/users/dickeyxxx/events{/privacy}","received_events_url":"https://api.github.com/users/dickeyxxx/received_events","type":"User","site_admin":false},"created_at":"2016-01-25T23:10:31Z","updated_at":"2016-01-25T23:10:31Z","body":"if you take these lines out it works: https://github.com/heroku/heroku-pipelines/blob/master/commands/pipelines/add.js#L40-L41"}}