Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1189

Better error handling for maximum call stack size errors

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: AsyncWriter
    • None
    • 8

      Originally reported as https://jira.mongodb.org/browse/SECURITY-789. Looks like both node.js REPL and the legacy shell had more graceful handling for maximum call stack size errors. MongoSH crashes, occasionally reporting a blob of generated code.

      To reproduce:

      function countdown(x) { if (!x) { return; } return countdown(x - 1); }
      

      Mongosh:

      > countdown(100000)
      REPL2:30
        const _arv = (async () => {
                      ^
      
      RangeError: Maximum call stack size exceeded
      (Use `node --trace-uncaught ...` to show where the exception was thrown)
      

      Node.js REPL:

      > countdown(100000)
      Uncaught RangeError: Maximum call stack size exceeded
          at countdown (REPL1:1:25)
          at countdown (REPL1:1:52)
          at countdown (REPL1:1:52)
          at countdown (REPL1:1:52)
          at countdown (REPL1:1:52)
          at countdown (REPL1:1:52)
          at countdown (REPL1:1:52)
          at countdown (REPL1:1:52)
          at countdown (REPL1:1:52)
          at countdown (REPL1:1:52)
      

      Legacy Shell

      > countdown(100000)
      uncaught exception: InternalError: too much recursion :
      countdown@(shell):1:52
      
      ...
      
      countdown@(shell):1:52
      countdown@(shell):1:52
      countdown@(shell):1:52
      > 
      

      Example from https://jira.mongodb.org/browse/SECURITY-789:

      > function testFn(){
      ...     let myrecursiveFn = () => {
      .....       let y = UUID();
      .....       return myrecursiveFn(1)
      .....   };
      ...     let x = myrecursiveFn(1);
      ...     return x;
      ... };
      
      > testFn();
      undefined:1
      var MongoshAsyncWriterError;function _slicedToArray(arr,i){"<async_rewriter>00660075006e006300740069006f006e0020005f0073006c00690063006500640054006f004100720072006100790028006100720072002c0020006900290020007b000a0020002000720065007400750072006e0020005f0061007200720061007900570069007400680048006f006c00650073002800610072007200290020007c007c0020005f006900740065007200610062006c00650054006f00410072007200610079004c0069006d006900740028006100720072002c0020006900290020007c007c0020005f0075006e0073007500700070006f0072007400650064004900740065007200610062006c00650054006f004100720072006100790028006100720072002c0020006900290020007c007c0020005f006e006f006e004900740065007200610062006c0065005200650073007400280029003b000a007d</>";const _sp=Symbol.for("@@mongosh.syntheticPromise")
      
      ....
      
      err);{if(_fs7==="sync"){_srv7=err;_fs7="threw";}else throw err;}}finally{if(_fs7!=="threw")_fs7="returned";}})();if(_fs7==="returned")return _srv7;else if(_fs7==="threw")throw _srv7;_fs7="async";return _msp7(_arv7);})();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
      
      RangeError: Maximum call stack size exceeded
      (Use `node --trace-uncaught ...` to show where the exception was thrown)
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            maurizio.casimirri@mongodb.com Maurizio Casimirri
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: