Skip to content

Commit

Permalink
Work around node.js bug nodejs/node-v0.x-archive#1669 where stdout bu…
Browse files Browse the repository at this point in the history
…ffer is not flushed at process exit and console.log()s performed by the application might not get printed. Fixes #2582
  • Loading branch information
juj committed Jul 27, 2014
1 parent 893b86f commit 90e9dd0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ function exit(status) {
exitRuntime();

if (ENVIRONMENT_IS_NODE) {
process['exit'](status);
// Work around a node.js bug where stdout buffer is not flushed at process exit:
// Instead of process.exit() directly, wait for stdout flush event.
// See https://github.com/joyent/node/issues/1669 and https://github.com/kripken/emscripten/issues/2582
// Workaround is based on https://github.com/RReverser/acorn/commit/50ab143cecc9ed71a2d66f78b4aec3bb2e9844f6
process.stdout.once('drain', function () {
process['exit'](status);
});
console.log(' '); // Make sure to print something to force the drain event to occur, in case the stdout buffer was empty.
} else if (ENVIRONMENT_IS_SHELL && typeof quit === 'function') {
quit(status);
} else {
Expand Down

0 comments on commit 90e9dd0

Please sign in to comment.