App just stops without any error information. Eg.
"use strict" ;
process.on('uncaughtException', function (exception) {
console.log(exception);
});
var count = 0 ;
function recursiveFunction(){
console.log(count++);
recursiveFunction();
}
recursiveFunction() ;
This will run so far then just stop. Try/Catch didn't work either - tried as above with ;
function recursiveFunction(){
console.log(count++);
try{
recursiveFunction();
}
catch(e){
console.log("recursion error");
}
}
Again nothing - just stops.
Have workaround ;
function recursiveFunction(){
console.log(count++);
setImmediate(recursiveFunction);
}
but original code should report error when fails.
Without console.log() call the error message is printed (with or without uncaughtException handler):
RangeError: Maximum call stack size exceeded
at recursiveFunction (test.js:8:27)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
With redirected stdout and without uncaughtException handler:
>test.js > out.log
util.js:597
function formatPrimitive(ctx, value) {
^
RangeError: Maximum call stack size exceeded
at formatPrimitive (util.js:597:25)
at formatValue (util.js:350:19)
at inspect (util.js:196:10)
at exports.format (util.js:68:24)
at Console.log (console.js:106:24)
at recursiveFunction (test.js:9:13)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
at recursiveFunction (test.js:10:5)
Yes, get the same here.
The code with console.log was to recreate something I'm getting in real code - which it does.
So it appears output - which I have in my real code via process.stdout.write mostly (and console.log in some cases though not called when error manifests ) affects the reporting of the recursion error.
I can reproduce on Windows, not on Linux.
I'd chalk this up as a known limitation. Since the stack is almost full, there is hardly anything you can do that won't raise another exception.
I have to disagree with you there bnoordhuis ; I'd say the behaviour should be consistent across implementations and scenarios and should report the error as it does on Linux or on Windows without the console.log call. I'd mark this as a bug.
(otherwise you have apps just stopping mid execution for no apparent reason with no way to find the fault bar an educated guess..)
I don't think you are hitting an actual stack overflow here, but rather a v8 limit, and it should be possible to report that. It is not like the process itself is out of memory, right?
cc @nodejs/v8
Let me amend: hardly anything you can do _in javascript_.
See #6899 for a similar bug report. Node.js already tries to do something meaningful on stack overflow but there isn't much wiggle room with a try/catch statement or process.on('uncaughtException') handler.
And for some more (and more recent) discussion: https://github.com/nodejs/node-v8/issues/5
I'm closing this as known limitation per my previous comments. If anyone has ideas on how to handle it better, please open a PR.
Most helpful comment
I have to disagree with you there bnoordhuis ; I'd say the behaviour should be consistent across implementations and scenarios and should report the error as it does on Linux or on Windows without the console.log call. I'd mark this as a bug.
(otherwise you have apps just stopping mid execution for no apparent reason with no way to find the fault bar an educated guess..)