-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Fix blocking / non-blocking stdio woes #3584
Comments
I've experienced a similar issue with stdio in Windows, and have somewhat worked around it in the meantime with this horrible, horrible hack. While my mini var exitHack = require('./exit').exit;
// If there are pending stdout / stderr writes when "condition" is met...
if (condition) {
exitHack();
}
// ...this code will still do something. Whoops!
doSomething(); I haven't seen this problem in OS X or Linux. It would be great if Node.js behaved the same cross-OS. |
Any update? Will this land in 0.10? |
This issue has been stagnant for months. In order for this to happen, it will need a champion. Are you that champion? Would you like to see stdio have a more consistently blocking/nonblocking interface, which works the same on Windows and Unix? Heed the call. Build the bits that need to go into libuv. Sketch out an API in node for it. It seems that it won't make the 0.10 cut-off, I'm afraid. Maybe next pass. |
I have started to look into this issue. Here is what I have found so far. I made a quick hack to simply let the Write operations execute synchronously when the pipe is in this mode. This approach means that stdout would have blocking IO behavior even when piped, without requiring any new API. Other pipes that have mode FILE_SYNCHRONOUS_IO_NONALERT or FILE_SYNCHRONOUS_IO_ALERT would also end up being blocking. Does this seem like an acceptable way of fixing this issue? |
Excellent! Any chance of getting this into node 0.10.x? This fix will allow me to get rid of ugly workarounds I need to use currently to not loose process output. |
@piscisaureus and/or @sblom: request for comment, please. |
Second pull request fixes commit message problems. |
@HenryRawas works with me. I'll look at thiS. |
Updated the proposed fix. Added API uv_pipe_setblocking() to libuv and changed windows pipe to use synchronous writes if this is set. Updated node code to call uv_pipe_setblocking() for stdio over pipe. |
@HenryRawas is it realistic to get this fix in for 0.10.x? |
I am still trying to get the change accepted. I don’t know where it will land. From: Benjamin Pasero [mailto:notifications@github.com] @HenryRawashttps://github.com/HenryRawas is it realistic to get this fix in for 0.10.x? — |
Just wanted to 👍 this issue. Was just bit by it in Windows 8 with Node v0.10.12. I'm still looking for a workaround atm. |
@jdalton Did you try the pipe to file workaround? |
@dcherman No I haven't. Did I miss it already covered? Here is what I'm trying to do. I noticed that the stdout var foo = cp.spawn(fooPath, fooOptions);
var output = '';
foo.stdout.on('data', function(data) {
output += data;
});
foo.on('exit', function() {
fs.writeFileSync(outputPath, output, 'utf8');
}); |
No matter what, don't do string concat like that. Use |
var logStream = fs.createWriteStream(outputPath);
foo.stdout.pipe(logStream);
foo.on('exit', function() {
// do some cleanup
});
|
Actually nix my issue. I tried it manually via the console and for some reason |
This works around a bug that's present in Node 0.8 and 0.10. This will likely be fixed in 0.12. nodejs/node-v0.x-archive#3584
- process.exit isn't properly waiting for buffers to finish writing in Windows - issue in node fixed in v0.11.12: nodejs/node-v0.x-archive#3584 Fixes #20
Output to stderr or stdout is not always completly written if you exit the process. Issue happens only on Windows using pipes. Issue nodejs/node-v0.x-archive#3584 will be fixed in node.js 0.12.
This is currently not working, awaits nodejs/node-v0.x-archive#3584
Hi, is this considered resolved? Is the use of https://github.com/cowboy/node-exit still recommended for some versions of node? |
Yes, it is resolved. It was fixed with 20176a9. |
Great, thanks! |
Issue still exists for me in 0.12.4, Windows 8.1: var child = require('child_process').spawn('php', Not sure if this is a bug, but if the process is infinite - then the child.stdout's callback is never triggered. |
I wrapped php process in another child script, now it works fine. |
Currently process.stdin / stdout / stderr is blocking, except when it is a pipe on windows. Weird and surprising. Very unpractical in cases where stdio is used as an IPC mechanism between node processes.
Discussion:http://logs.nodejs.org/libuv/2012-06-29#00:40:38.256
Preliminary results: have
process.stdout.setBlocking(true|false)
orprocess.stdout.writeSync.
Feel free to post thoughts here.
The text was updated successfully, but these errors were encountered: