Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console.log / console.error are supposedly synchronous, but huge amounts of trailing data can be lost on process.exit #7743

Closed
ghost opened this issue Jul 15, 2016 · 9 comments
Labels
question Issues that look for answers. tty Issues and PRs related to the tty subsystem.

Comments

@ghost
Copy link

ghost commented Jul 15, 2016

  • Version: v6.3.0
  • Platform: Linux cyberman 4.5.5-300.fc24.x86_64 deps: update openssl to 1.0.1j #1 SMP Thu May 19 13:05:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: ???

I read on various sites that console.log is supposed to be synchronous in recent node.js versions. I just want to write a simple application that writes things to the terminal and exits.

However, as you can see with this simple example, huge amounts of output can be missing when simply using console.log and exiting:

var s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

for (var i = 0; i < 99999; i++) {
    console.log (i + "  " + s);
}
console.log ("pink");
console.error ("punk");
process.exit(0);

If you run it multiple times, you'll also get very random cutoffs for the stdout data. That goes completely against my expectations of a supposedly synchronous function..

How can console.log be used for safe output that actually arrives even when exiting the program? I would do a flush before exit, if I knew how..

@mscdex
Copy link
Contributor

mscdex commented Jul 15, 2016

I believe the changes made were only for OS X.

/cc @Fishrock123

@mscdex mscdex added question Issues that look for answers. tty Issues and PRs related to the tty subsystem. labels Jul 15, 2016
@Fishrock123
Copy link
Contributor

@nodejs/ctc and here's another report on why we definitely need to do #6816 ...

Fishrock123 added a commit to Fishrock123/node that referenced this issue Jul 18, 2016
addaleax pushed a commit that referenced this issue Aug 10, 2016
Refs: #1771
Refs: #6456
Refs: #6773
Refs: #7743
PR-URL: #6816
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: James M Snell <[email protected]>
cjihrig pushed a commit that referenced this issue Aug 11, 2016
Refs: #1771
Refs: #6456
Refs: #6773
Refs: #7743
PR-URL: #6816
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: James M Snell <[email protected]>
jmlopez-rod pushed a commit to iOffice/ts-publish that referenced this issue Nov 1, 2016
This seems to be due to a node issue:
nodejs/node#7743
@ghost
Copy link
Author

ghost commented Jan 1, 2017

Since #6816 was closed, I believe this is now also solved.

@ghost ghost closed this as completed Jan 1, 2017
@buckles1170
Copy link

I'm still getting this issue on node 10.9.0

@buckles1170
Copy link

pinging @graingert

@refack
Copy link
Contributor

refack commented Aug 21, 2018

Hello @buckles1170 and thank you for the report.
Could you provide more information on the circumstances in which you experience this issue. Possibly open a new bug report?
Helpful information might be, OS, some minimal code, are you running with NODE_TTY_UNSAFE_ASYNC and are your STDOUT/ERR connected to TTYs?

@graingert
Copy link

We're running on gitlab CI with the node:10 docker image, I can't repeat it locally.

I've not configured anything like NODE_TTY_UNSAFE_ASYNC

@refack
Copy link
Contributor

refack commented Aug 21, 2018

@graingert, my guess is that running in a CI has STDOUT and STDERR piped into files (or even something more complex), so they are not TTY, and NODE_TTY_UNSAFE_ASYNC is not relevant anyway.
In that case it might not be a Node.js problem but a race in the wrapper. It's possible that node pushed the data out before exiting, but the receiver did not update the log before it detected that the node process exited. I'm not sure that is the case, but it's possible.
I can imagine a workaround with piping STDOUT & STDERR to files, then cating the file to the log (or using tee).

@graingert
Copy link

This is running under npm run, and I get the little message from npm too

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers. tty Issues and PRs related to the tty subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants