-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Lost stdout output when executed through child_process.spawn #120
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
Comments
Could you make this a pull request? |
Will do. Thanks |
Fixes issue cucumber#120
Fix for issue cucumber#120
I've found that resource leaks (thinks that keep the event loop active) can cause cucumber-js to never exit. The fix is to replace var code = succeeded ? 0 : 1;
process.on('exit', function() {
process.exit(code);
}); with var code = succeeded ? 0 : 1;
process.on('exit', function() {
process.exit(code);
});
var timeoutId = setTimeout(function () {
console.error('Cucumber process timed out after waiting 60 seconds for the node.js event loop to empty. There may be a resource leak. Have all resources like database connections and network connections been closed properly?');
process.exit(code);
}, 60 * 1000);
if (timeoutId.unref) {
timeoutId.unref();
}
else {
clearTimeout(timeoutId);
} This is compatible with old and new versions of node but you only get the benefit of the timeout with node 0.10 onwards (see the |
Hi Simon, Is this still relevant? Also, I'm thinking the warning message and the timeout could become pretty annoying when testing applications with servers running. An express application, for example, will not let the event loop empty and forcing a WDYT? |
@simondean Please reopen if you still experience this issue. |
Hi Simon and Julien, Cheers |
I spent ages doing the wrong setup for AfterFeatures to try and close my browser at the end of the tests, so I thought that including a test and better documentation might help other people. This also fixes the unimplemented cli.feature step, and failing assert due to console coloring. I had to apply the patch from comments in #120 to get these tests to run correctly. Conflicts: bin/cucumber.js features/cli.feature features/step_definitions/cli_steps.js
I'm still experiencing this problem. When i run require('cucumber').Cli(specs).run(function (succeeded) {
var code = succeeded ? 0 : 1;
process.on('exit', function () {
console.log('exiting')
process.exit(code);
});
var timeoutId = setTimeout(function () {
console.error('Cucumber process timed out after waiting 60 seconds for the node.js event loop to empty. There may be a resource leak. Have all resources like database connections and network connections been closed properly?');
process.exit(code);
}, 60 * 1000);
if (timeoutId.unref) {
timeoutId.unref();
}
else {
clearTimeout(timeoutId);
}
}); And a test fails, nothing is logged. I am trying to log the duration of the tests right before Not sure if this issue needs reopening, or if maybe theres a bug in my code but for whatever reason I can't catch process.on('exit') |
@joshtombs Which version of node.js are you using? |
@simondean v0.10.29 |
process.on('exit') will only fire when the node.js event loop is empty. Having something like an open database or HTTP connection will prevent the process from exiting. Does the timeout fire? Do you see the output from the console.error? |
Above is what's being outputted from terminal. As you can see my test failed and the error was reported. The feature file finished, and this is at the end of the "(::) failed steps (::)" report. It displays the error and then exits. The log isnt being hit in process.on('exit', function(){
console.log('exiting');
process.exit(code)
}); Then as shown when I check the status of the previous exit it is 0. Thanks! |
Is Does it work properly if you use the offical bin for cucumber-js? E.g. |
Yeah, so I forked cucumber-js and ran the default cucumber-js That said, I am using cucumber-js inside a project that I'm working on, which can just be thought of as a layer that sits on top of cucumber right now. I would like to be able to pass my own callback function to the runtime, so that is why I am just calling |
Does it sound like the bug is maybe in your code then? It's worth checking you don't have more than 1 listener for the process exit event. It's worth checking the docs for the exit event too: http://nodejs.org/api/process.html#process_event_exit It gives some guidance for things not to do in an exit listener. Calling process.exit from the exit event is really trick. The process would have exited anyway, the trick just provides a way to change the exit code from the default of zero. |
@simondean you were right! So after digging further into our code, I noticed that we were using our own
and not actually calling that callback function! so the tree walker wasn't actually finishing. Thanks for the help |
Cucumber hanging 60sec is quite annoying, there is no way to know what ressource is keeping the event loop busy and a lot of modules (ex. connect-mongostore, zombiejs) don't provide a way to clean their ressource(s). |
For mongoose you can do:
|
I also think that this 60 second exit timeout is very annoying, especially if you cannot tell what causes your resource leak. Or this would trace back to the original stdout lost issue? |
@zs-zs node.js does not finish processing the event loop or flush any output to STDOUT or STDERR when you call process.exit(); I can't remember whether this is a Windows specific issue or affects other OSs too See nodejs/node-v0.x-archive#3737 for more info |
@zs-zs The timeout seemed to be the best compromise, I'm not so sure anymore as it made Cucumber responsible for user land leaked resource management and that arbitrary timeout is indeed annoying. I've reverted back to a non-timeout approach on master. @simondean @zs-zs @kaworu please give it a try and tell us if it awakes old demons. @simondean I've used your flush test script against that new code:
|
Thanks @kaworu. That's one happy person, right. Who's next? :) |
Closing as this issue moves through a few different solutions that span over a couple years. If you are still experiencing this issue with the latest versions, please open a new issue |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi. I'm writing a node module for executing cucumber-js features across multiple processes and multiple machines. I've hit an issue when executing cucumber-js via child_proces.spawn. 5-15% of the time, cucumber-js exits without outputting anything to stdout (normally I'm using the JSON formatter).
You can see the bug by running the following code (spawn_cucumber.js):
There's also a copy of the above code here: git://github.com/simondean/node-spawn-lost-output-bug.git
Here's some example ouput:
The issue is in bin/cucumber.js:
If the above is replaced with the following it fixes the issue:
Thanks
Simon
The text was updated successfully, but these errors were encountered: