Skip to content

recursion error not reported #14311

Description

@bobOnGitHub
  • 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.

Activity

  1. added
    questionIssues asking questions about Node.js.
    on Jul 16, 2017
  2. vsemozhetbyt commented on Jul 16, 2017

    @vsemozhetbyt
    Contributor

    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)
  3. vsemozhetbyt commented on Jul 16, 2017

    @vsemozhetbyt
    Contributor

    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)
  4. bobOnGitHub commented on Jul 16, 2017

    @bobOnGitHub
    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.

  5. added
    windowsIssues and PRs related to the Windows platform.
    on Jul 16, 2017
  6. tniessen commented on Jul 16, 2017

    @tniessen
    Member

    I can reproduce on Windows, not on Linux.

  7. bnoordhuis commented on Jul 17, 2017

    @bnoordhuis
    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.

  8. bobOnGitHub commented on Jul 17, 2017

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

  9. tniessen commented on Jul 17, 2017

    @tniessen
    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

  10. bnoordhuis commented on Jul 17, 2017

    @bnoordhuis
    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.

  11. bnoordhuis commented on Jul 17, 2017

    @bnoordhuis
    Member

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

  12. bnoordhuis commented on Aug 3, 2017

    @bnoordhuis
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    known limitationIssues that are identified as known limitations.questionIssues asking questions about Node.js.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions