{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/node/pulls/comments/63560593","id":63560593,"diff_hunk":"@@ -145,7 +145,69 @@ function setupKillAndExit() {\n       process._exiting = true;\n       process.emit('exit', process.exitCode || 0);\n     }\n+\n+    // Flush stdio streams prior to exit.\n+    // `flushSync` not present if stream redirected to file in shell.\n+    flushSync(process.stdout);\n+    flushSync(process.stderr);\n+\n     process.reallyExit(process.exitCode || 0);\n+\n+    function flushSync(stream) {\n+\n+      // Behavior of this function outside of process.exit() is undefined\n+      // due to the following factors:\n+      // * Stream fd may be blocking after this call.\n+      // * In the event of an incomplete flush pending buffered write\n+      //   requests may be truncated.\n+      // * No return code.\n+\n+      if (stream._writev)\n+        return;\n+\n+      var handle = stream._handle;\n+      if (!handle || !handle.flushSync)\n+        return;\n+\n+      var fd = handle.fd;\n+      if (typeof fd !== 'number' || fd < 0)\n+        return;\n+\n+      // FIXME: late module resolution avoids cross require problem\n+      const fs = require('fs');\n+\n+      const Buffer = require('buffer');\n+\n+      // Queued libuv writes must be flushed first.\n+      // Note: fd will set to blocking after handle.flushSync()\n+      if (handle.flushSync() !== 0) {\n+        // bad fd or write queue for libuv stream not entirely flushed\n+        return;\n+      }\n+\n+      // then the queued stream chunks can be flushed\n+      var state = stream._writableState;\n+      var entry = state.bufferedRequest;\n+      while (entry) {\n+        var chunk = entry.chunk;\n+        if (!(chunk instanceof Buffer)) {\n+          chunk = Buffer.from(chunk, entry.encoding);\n+        }\n+        // Note: fd is blocking at this point\n+        var written = fs.writeSync(fd, chunk, 0, chunk.length);","path":"lib/internal/process.js","position":53,"original_position":53,"commit_id":"2f6420ba38ab8ccaab3426c49b36484eafeb8e95","original_commit_id":"2f6420ba38ab8ccaab3426c49b36484eafeb8e95","user":{"login":"Fishrock123","id":1093990,"avatar_url":"https://avatars.githubusercontent.com/u/1093990?v=3","gravatar_id":"","url":"https://api.github.com/users/Fishrock123","html_url":"https://github.com/Fishrock123","followers_url":"https://api.github.com/users/Fishrock123/followers","following_url":"https://api.github.com/users/Fishrock123/following{/other_user}","gists_url":"https://api.github.com/users/Fishrock123/gists{/gist_id}","starred_url":"https://api.github.com/users/Fishrock123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fishrock123/subscriptions","organizations_url":"https://api.github.com/users/Fishrock123/orgs","repos_url":"https://api.github.com/users/Fishrock123/repos","events_url":"https://api.github.com/users/Fishrock123/events{/privacy}","received_events_url":"https://api.github.com/users/Fishrock123/received_events","type":"User","site_admin":false},"body":"> but probably TTYs needs to be rethinked a bit.\r\n\r\nI agree, the current code for all these different things is a mess, but that's not something we are in a position to immediately refactor I think.","created_at":"2016-05-17T16:53:45Z","updated_at":"2016-05-17T16:53:45Z","html_url":"https://github.com/nodejs/node/pull/6773#discussion_r63560593","pull_request_url":"https://api.github.com/repos/nodejs/node/pulls/6773","_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments/63560593"},"html":{"href":"https://github.com/nodejs/node/pull/6773#discussion_r63560593"},"pull_request":{"href":"https://api.github.com/repos/nodejs/node/pulls/6773"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/6773","id":70125762,"html_url":"https://github.com/nodejs/node/pull/6773","diff_url":"https://github.com/nodejs/node/pull/6773.diff","patch_url":"https://github.com/nodejs/node/pull/6773.patch","issue_url":"https://api.github.com/repos/nodejs/node/issues/6773","number":6773,"state":"open","locked":false,"title":"process: flush stdout/stderr upon `process.exit()`","user":{"login":"Fishrock123","id":1093990,"avatar_url":"https://avatars.githubusercontent.com/u/1093990?v=3","gravatar_id":"","url":"https://api.github.com/users/Fishrock123","html_url":"https://github.com/Fishrock123","followers_url":"https://api.github.com/users/Fishrock123/followers","following_url":"https://api.github.com/users/Fishrock123/following{/other_user}","gists_url":"https://api.github.com/users/Fishrock123/gists{/gist_id}","starred_url":"https://api.github.com/users/Fishrock123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fishrock123/subscriptions","organizations_url":"https://api.github.com/users/Fishrock123/orgs","repos_url":"https://api.github.com/users/Fishrock123/repos","events_url":"https://api.github.com/users/Fishrock123/events{/privacy}","received_events_url":"https://api.github.com/users/Fishrock123/received_events","type":"User","site_admin":false},"body":"WIP _**Do not Merge**_\r\n\r\n<!--\r\nThank you for submitting a pull request to Node.js. Before you submit, please\r\nreview below requirements and walk through the checklist. You can 'tick'\r\na box by using the letter \"x\": [x].\r\n\r\nRun the test suite by invoking: `make -j4 lint test` on linux or\r\n`vcbuild test nosign` on Windows.\r\n\r\nIf this aims to fix a regression or you’re adding a feature, make sure you also\r\nwrite a test. Finally – if possible – a benchmark that quantifies your changes.\r\n\r\nFinally, read through our contributors guide and make adjustments as necessary:\r\nhttps://github.com/nodejs/node/blob/master/CONTRIBUTING.md\r\n-->\r\n\r\n##### Checklist\r\n\r\n<!-- remove lines that do not apply to you -->\r\n\r\n- [ ] tests and code linting passes\r\n- [X] a test and/or benchmark is included\r\n- [ ] documentation is changed or added\r\n- [X] the commit message follows commit guidelines\r\n\r\n\r\n\r\n<!-- provide a description of the change below this comment -->\r\nProposed fix for https://github.com/nodejs/node/issues/6456\r\n\r\nAdapted from https://github.com/kzc/node/commit/29997921800e00a22d9f92d24704a0021be03bbf without exposing a new streams API.\r\n\r\nDone on a public branch in case someone else needs to take it over.\r\n\r\nInitial CI: https://ci.nodejs.org/job/node-test-pull-request/2650/","created_at":"2016-05-15T16:26:54Z","updated_at":"2016-05-17T16:53:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2b0245e525bb507778f461dd8177755ed3b50dc4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/node/pulls/6773/commits","review_comments_url":"https://api.github.com/repos/nodejs/node/pulls/6773/comments","review_comment_url":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/node/issues/6773/comments","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/2f6420ba38ab8ccaab3426c49b36484eafeb8e95","head":{"label":"nodejs:process-exit-stdio-flushing","ref":"process-exit-stdio-flushing","sha":"2f6420ba38ab8ccaab3426c49b36484eafeb8e95","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":27193779,"name":"node","full_name":"nodejs/node","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":false,"url":"https://api.github.com/repos/nodejs/node","forks_url":"https://api.github.com/repos/nodejs/node/forks","keys_url":"https://api.github.com/repos/nodejs/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/node/teams","hooks_url":"https://api.github.com/repos/nodejs/node/hooks","issue_events_url":"https://api.github.com/repos/nodejs/node/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/node/events","assignees_url":"https://api.github.com/repos/nodejs/node/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/node/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/node/tags","blobs_url":"https://api.github.com/repos/nodejs/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/node/languages","stargazers_url":"https://api.github.com/repos/nodejs/node/stargazers","contributors_url":"https://api.github.com/repos/nodejs/node/contributors","subscribers_url":"https://api.github.com/repos/nodejs/node/subscribers","subscription_url":"https://api.github.com/repos/nodejs/node/subscription","commits_url":"https://api.github.com/repos/nodejs/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/node/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/node/merges","archive_url":"https://api.github.com/repos/nodejs/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/node/downloads","issues_url":"https://api.github.com/repos/nodejs/node/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/node/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/node/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/node/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/node/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/node/deployments","created_at":"2014-11-26T19:57:11Z","updated_at":"2016-05-17T16:20:24Z","pushed_at":"2016-05-17T15:42:34Z","git_url":"git://github.com/nodejs/node.git","ssh_url":"git@github.com:nodejs/node.git","clone_url":"https://github.com/nodejs/node.git","svn_url":"https://github.com/nodejs/node","homepage":"https://nodejs.org","size":267150,"stargazers_count":23240,"watchers_count":23240,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3300,"mirror_url":null,"open_issues_count":673,"forks":3300,"open_issues":673,"watchers":23240,"default_branch":"master"}},"base":{"label":"nodejs:master","ref":"master","sha":"477d35848c33e3e5cb7643a11973e5504f659581","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":27193779,"name":"node","full_name":"nodejs/node","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/node","description":"Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:","fork":false,"url":"https://api.github.com/repos/nodejs/node","forks_url":"https://api.github.com/repos/nodejs/node/forks","keys_url":"https://api.github.com/repos/nodejs/node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/node/teams","hooks_url":"https://api.github.com/repos/nodejs/node/hooks","issue_events_url":"https://api.github.com/repos/nodejs/node/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/node/events","assignees_url":"https://api.github.com/repos/nodejs/node/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/node/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/node/tags","blobs_url":"https://api.github.com/repos/nodejs/node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/node/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/node/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/node/languages","stargazers_url":"https://api.github.com/repos/nodejs/node/stargazers","contributors_url":"https://api.github.com/repos/nodejs/node/contributors","subscribers_url":"https://api.github.com/repos/nodejs/node/subscribers","subscription_url":"https://api.github.com/repos/nodejs/node/subscription","commits_url":"https://api.github.com/repos/nodejs/node/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/node/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/node/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/node/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/node/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/node/merges","archive_url":"https://api.github.com/repos/nodejs/node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/node/downloads","issues_url":"https://api.github.com/repos/nodejs/node/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/node/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/node/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/node/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/node/releases{/id}","deployments_url":"https://api.github.com/repos/nodejs/node/deployments","created_at":"2014-11-26T19:57:11Z","updated_at":"2016-05-17T16:20:24Z","pushed_at":"2016-05-17T15:42:34Z","git_url":"git://github.com/nodejs/node.git","ssh_url":"git@github.com:nodejs/node.git","clone_url":"https://github.com/nodejs/node.git","svn_url":"https://github.com/nodejs/node","homepage":"https://nodejs.org","size":267150,"stargazers_count":23240,"watchers_count":23240,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3300,"mirror_url":null,"open_issues_count":673,"forks":3300,"open_issues":673,"watchers":23240,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/node/pulls/6773"},"html":{"href":"https://github.com/nodejs/node/pull/6773"},"issue":{"href":"https://api.github.com/repos/nodejs/node/issues/6773"},"comments":{"href":"https://api.github.com/repos/nodejs/node/issues/6773/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/node/pulls/6773/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/node/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/node/pulls/6773/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/node/statuses/2f6420ba38ab8ccaab3426c49b36484eafeb8e95"}}}}