-
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
documentation on Stream.write misses that callback does not ensure that data written to process.stdout/.stderr is flushed #3670
Comments
Oh - and to be a bit bitchy - either this or #3669 and related must be open. I would suggest to open the other ones again as just fixing the docs would mean that node.js is unusable for implementing cli tools. |
@minesworld please don't open duplicates, we can re-open issues if necessary. :) The "fix" is #3170, i.e. fix the docs.
You don't have to use The exact reason that it doesn't get written has something to do with chunked writes far lower down, probably near the OS layer. I'm not sure if this is actually properly fixable in libuv, see #1771 (comment) and libuv/libuv#428 -- ideally it's up to your application. In this case it means not immediately terminating the process on write. @minesworld I haven't seen this happen for not-chunked writes before, perhaps that has to do with exiting in the cllback. Could you try wrapping the Another option would be a |
Can I suggest we close this bug report? It's a known issue with several open bug reports. This one doesn't add anything new. |
@bnoordhuis maybe we should add this to the |
Good idea. |
Do node.js a favour by:
Putting it into known issues would be a just "OK" solution. But writing it into the docs gives it the prominent place it deserves. Because this behaviour is totally against the docs. It doesn't matter that you shouldn't call process.exit(), the code before should have ensured that all data to stdio is flushed. Also sometimes it isn't possible to not call process.exit(). I've looked at the node and libuv code but didn't get my head around it yet. Here are some suggestions which might help:
|
I just want to express my thanks for NOT closing this issue and thinking about re-opening other issues again. This here shouldn't have happened at all as I was the n person who experienced it and "wasted" a lot of time. But better late then never. For all of us out there using node.js a bit "different" - in my case its a ssh2 client - having these informations is really really crucial as it might affect the design phase etc. Thats why I urge to put it into the docs... |
If there is nobody to want to change the docs, let me know - I will fork it and do it for you. At the moment I'm a bit under stress getting my ssh2 client working reliable as my current workaround to wait a bit for the data to be flushed before process.exit() needs some more work (as expected...) |
What's an example? I can't think of one unless your program is written such that you'd need to exit immediately to prevent other async calls for some reason.
@minesworld most of us a pretty busy and definitely wouldn't mind that. :) |
@Fishrock123 when you haven't control over what other libraries are keeping in the background running... I will fork node.js and update the docs ... At the moment I'm using a workaround by listening on a pipe before process.stdout/.stderr to end and then wait 10 seconds before calling process.exit(). Its ugly and only 99,99% reliable and a waste of time if nothing big was written firsthand... but at least its working better than not using it. |
Created a pull request: #3772 Hope that letting Node.js ending itself really ensures that all data to process.stdout/.stderr is flushed... |
I think this can be closed because all the relevant activity seems to be at #6456 and this issue has been dormant for nearly 7 months. Feel free to re-open (or comment asking that it be re-opened) if you disagree. |
doesn't reliable ensure that a consumer of node.js will get all data (yes - it is a PIPE, not a FILE !!).
The text was updated successfully, but these errors were encountered: