-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
A libuv upgrade in Node v6 breaks the popular david package #6297
Comments
/cc @saghul |
@mgol It could be a tty issue in libuv 1.9.0. Can you try running:
or
|
|
I can reproduce your original truncated |
I'll take a look. Main suspect: libuv/libuv@387102b |
I'm on latest 10.11.4. I tried both in ZSH & Bash, same results every time. |
If I apply this patch to master then
|
@saghul Might be an issue with |
scratch that - |
If this patch is applied to master with libuv 1.9.0 then diff --git a/deps/uv/src/unix/tty.c b/deps/uv/src/unix/tty.c
index 32fa37e..9179ca7 100644
--- a/deps/uv/src/unix/tty.c
+++ b/deps/uv/src/unix/tty.c
@@ -135,8 +135,10 @@ skip:
else
flags |= UV_STREAM_WRITABLE;
+#if 0
if (!(flags & UV_STREAM_BLOCKING))
uv__nonblock(fd, 1);
+#endif
uv__stream_open((uv_stream_t*) tty, fd, flags);
tty->mode = UV_TTY_MODE_NORMAL; |
/cc @Gottox |
I don't think the libuv tty PR is the issue. It appears that process.stdout is not being flushed upon process exit. Making stdout blocking as per patch above can make it work, but that's just side stepping the real issue. If the What is considered to be the correct node way of flushing stdout upon |
Alternate fix - leave node 6.0.0-rc with libuv 1.9.0 as is and simply apply this patch to
This has the effect of letting the program exit naturally without abruptly cutting off the flushing of stdout. |
The not flushing on exit is a bit of a long standing issue. It's on my list of things to get figured out soon-ish. In the meantime, it's possible to register an on-exit handler that can flush but you'll need to make sure everything gets done in a single go as there's no ability to nextTick or setImmediate... Node will exit immediately after the on-exit handlers are called. If you have control over when process.exit() is called, you can orchestrate a graceful exit (see #6175 for an example). |
See also: https://github.com/cowboy/node-exit If In light of these workarounds I think this node ticket can be closed and no need to revert libuv 1.9.0. |
Interesting. Why isn't this an issue in Node <6 then? |
I have to admit that the current node behavior of |
Not entirely certain but I believe this libuv update included some changes I'm investigating ways of allowing Node to make a more graceful exit, but
|
Any chance this can be reproduced only with core modules? |
I'm sure given enough time it could be isolated into a standalone test case, but a simple print loop is insufficient to reproduce the issue. The higher level question that should be addressed before any fix is attempted is whether |
The key challenge to making |
That's the thing, |
+1. the documentation could indeed be made significant better here. Interested in doing a pull request? ;-) ... if not, maybe someone from @nodejs/documentation could look into it :-) |
I honestly do not know what is considered the best node practise to flush stdout/stderr upon But I agree with you that |
hmm. No expert and I trust you. It wouldn't jump to main though but to right after |
@bnoordhuis Right, but the suggestion to use longjmp wasn't necessarily playing towards destructors, but rather avoiding a call to There is a better way to handle this function. That's all I'm getting at. |
If you look to C and libc for historical inspiration (not implementation) there's Obviously node's |
@kzc There is, it's just not being used to flush streams. process.exit(0); // exit, but with a little bit of cleanup
process.reallyExit(0); // exit(0); See #6297 (comment) |
Apparent consensus is that the present behavior of Something logically equivalent to this user code polyfill using the third party exit module that is already known to work:
There's not much code there: https://github.com/cowboy/node-exit/blob/master/lib/exit.js |
@kzc while that's a perfectly fine temporary solution, this is a simple problem within Node proper and should be fixed :P I don't think it's a consensus that |
@kzc ... I had a proposed PR that did exactly that but the consensus was that it's something that can be easily handled in userland. Essentially, if you want to exit gracefully while letting any stdio finish, you'll need to make sure that you're not adding anything to the event loop queue so that the process exits out on it's own naturally. |
Exiting on its own naturally doesn't work in practise with complicated nested async logic without rewriting a lot of code. So if something like |
@jasnell while I agree that's what users should be doing, the fact is that Node is being used as a scripting language and thus is more prone to users using pre-mature Since |
@Qix- ... I agree with you :-) ... just need a PR that implements a solution that would be accepted. |
@jasnell Haha okay :) 👍 |
@kzc I also see the need to handle this better and have it on my list, or would welcome a decent PR . Can we close this issue or give it a proper name that reflects what the discussion was about though? |
@eljefedelrodeodeljefe What would you do differently than https://github.com/cowboy/node-exit/blob/master/lib/exit.js Looks good to me, and it's known to work. Even supports closing streams other than |
@mgol Would you mind renaming this issue to something like "process.exit() ought to flush stdout/stderr"? |
I'd be more inclined to close this particular issue as we have a couple others already in the tracker for this particular issue. The libuv update just brought the issue more to the forefront. |
Well, |
@kzc because their is no action item for Concerning reopen if you don't agree, but I think this can be closed in favor for #6456 |
Unfortunately I don't have an isolated test case, I've only seen the
david
issue in all v6 RCs while it works fine in v5 & I reported it in alanshaw/david#106. I did agit bisect
, though and nailed it down to c3cec1e.The text was updated successfully, but these errors were encountered: