Skip to content
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

recursion error not reported #14311

Closed
bobOnGitHub opened this issue Jul 16, 2017 · 10 comments
Closed

recursion error not reported #14311

bobOnGitHub opened this issue Jul 16, 2017 · 10 comments
Labels
known limitation Issues that are identified as known limitations. question Issues that look for answers. windows Issues and PRs related to the Windows platform.

Comments

@bobOnGitHub
Copy link

bobOnGitHub commented Jul 16, 2017

  • Version: 6.11.0
  • Platform: Windows 10 64 bit
  • Subsystem:

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.

@mscdex mscdex added the question Issues that look for answers. label Jul 16, 2017
@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jul 16, 2017

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)

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jul 16, 2017

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)

@bobOnGitHub
Copy link
Author

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.

@tniessen tniessen added the windows Issues and PRs related to the Windows platform. label Jul 16, 2017
@tniessen
Copy link
Member

I can reproduce on Windows, not on Linux.

@bnoordhuis bnoordhuis added the known limitation Issues that are identified as known limitations. label Jul 17, 2017
@bnoordhuis
Copy link
Member

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.

@bobOnGitHub
Copy link
Author

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..)

@tniessen
Copy link
Member

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

@bnoordhuis
Copy link
Member

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.

@bnoordhuis
Copy link
Member

And for some more (and more recent) discussion: nodejs/node-v8#5

@bnoordhuis
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
known limitation Issues that are identified as known limitations. question Issues that look for answers. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

5 participants