Skip to content

Commit 90e9dd0

Browse files
committedJul 27, 2014
Work around node.js bug nodejs/node-v0.x-archive#1669 where stdout buffer is not flushed at process exit and console.log()s performed by the application might not get printed. Fixes #2582
1 parent 893b86f commit 90e9dd0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎src/postamble.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,14 @@ function exit(status) {
175175
exitRuntime();
176176

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

0 commit comments

Comments
 (0)