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

Maximum call stack error #474

Closed
dmamalis opened this issue Oct 9, 2014 · 8 comments
Closed

Maximum call stack error #474

dmamalis opened this issue Oct 9, 2014 · 8 comments

Comments

@dmamalis
Copy link

dmamalis commented Oct 9, 2014

...every time i try to print a result from a MongoDB to the console.
At first I thought it could be the size of information printed. Then I tried to print a single object and the error showed up again. This is what i get when i try to print on the console with
logger.verbose(result[0])

{ '$__': 
    { strictMode: true,
     selected: undefined,
     shardval: undefined,
     saveError: undefined,
     validationError: undefined,
     adhocPaths: undefined,
     removing: undefined,
     inserting: undefined,
     version: undefined,
     getters: {},
     _id: undefined,
     populate: undefined,
     populated: undefined,
     wasPopulated: false,
     scope: undefined,
     activePaths: 
      { paths: 
         { 'location.coordinates': 'init',
           __v: 'init',
           'properties.name': 'init',
           'geometry.type': 'init',
           _id: 'init' },
        states: 
         { ignore: {},
           default: {},
           init: 
            { __v: true,
              'properties.name': true,
              'geometry.coordinates': true,
              'geometry.type': true,
              _id: true },
           modify: {},
           require: {} },
        stateNames: 
         [ 'require',
           'modify',
           'init',
           'default',
           'ignore' ] },
     ownerDocument: undefined,
     fullPath: undefined },
  isNew: false,
  errors: undefined,
  _maxListeners: 0,
  _doc: 
   { properties: 
      { name: 'xxx',
        id: 'xx',
        obj: 'xxxxxx' },
     geometry: 
      { coordinates: [ 89.90272, 42.2913 ],
        type: 'Point' },
     __v: 0,
     _id: 
      { _bsontype: 'ObjectID',
        id: 'T6S%\u0014\u0010è\u0007t­uH' } },
  _pres: 
   { save: 
      [ { [Function] isAsync: false },
        { [Function: checkForExistingErrors] isAsync: false },
        { [Function: validation] isAsync: false } ] },
  _posts: { save: [] },
  save: { [Function] numAsyncPres: 0 },
  _events: {} }
2014-10-09T11:14:48.778Z - error: uncaughtException: Maximum call stack size exceeded 
@wclr
Copy link

wclr commented Jun 26, 2015

something like that happens:

^, $__original_save=function () {
      var self = this
        , hookArgs // arguments eventually passed to the hook - are mutable
        , lastArg = arguments[arguments.length-1]
        , pres = this._pres[name]
        , posts = this._posts[name]
        , _total = pres.length
        , _current = -1
        , _asyncsLeft = proto[name].numAsyncPres
        , _asyncsDone = function(err) {
            if (err) {
              return handleError(err);
            }
            --_asyncsLeft || _done.apply(self, hookArgs);
          }
        , handleError = function(err) {
            if ('function' == typeof lastArg)
              return lastArg(err);
            if (errorCb) return errorCb.call(self, err);
            throw err;
          }
        , _next = function () {
            if (arguments[0] instanceof Error) {
              return handleError(arguments[0]);
            }
            var _args = Array.prototype.slice.call(arguments)
              , currPre
              , preArgs;
            if (_args.length && !(arguments[0] == null && typeof lastArg === 'function'))
              hookArgs = _args;
            if (++_current < _total) {
              currPre = pres[_current]
              if (currPre.isAsync && currPre.length < 2)
                throw new Error("Your pre must have next and done arguments -- e.g., function (next, done, ...)");
              if (currPre.length < 1)
                throw new Error("Your pre must have a next argument -- e.g., function (next, ...)");
              preArgs = (currPre.isAsync
                          ? [once(_next), once(_asyncsDone)]
                          : [once(_next)]).concat(hookArgs);
              return currPre.apply(self, preArgs);
            } else if (!_asyncsLeft) {
              return _done.apply(self, hookArgs);
            }
          }
        , _done = function () {
            var args_ = Array.prototype.slice.call(arguments)
              , ret, total_, current_, next_, done_, postArgs;

            if (_current === _total) {

              next_ = function () {
                if (arguments[0] instanceof Error) {
                  return handleError(arguments[0]);
                }
                var args_ = Array.prototype.slice.call(arguments, 1)
                  , currPost
                  , postArgs;
                if (args_.length) hookArgs = args_;
                if (++current_ < total_) {
                  currPost = posts[current_]
                  if (currPost.length < 1)
                    throw new Error("Your post must have a next argument -- e.g., function (next, ...)");
                  postArgs = [once(next_)].concat(hookArgs);
                  return currPost.apply(self, postArgs);
                } else if (typeof lastArg === 'function'){
                  // All post handlers are done, call original callback function
                  return lastArg.apply(self, arguments);
                }
              };

              // We are assuming that if the last argument provided to the wrapped function is a function, it was expecting
              // a callback.  We trap that callback and wait to call it until all post handlers have finished.
              if(typeof lastArg === 'function'){
                args_[args_.length - 1] = once(next_);
              }

              total_ = posts.length;
              current_ = -1;
              ret = fn.apply(self, args_); // Execute wrapped function, post handlers come afterward

              if (total_ && typeof lastArg !== 'function') return next_();  // no callback provided, execute next_() manually
              return ret;
            }
          };

      return _next.apply(this, arguments);
    }, save=function wrappedPointCut() {
      var args = [].slice.call(arguments);
      var lastArg = args.pop();

      var wrapingPromise = new Promise;
      wrapingPromise.end();
      if (typeof lastArg == 'function') {
        wrapingPromise.onResolve(lastArg);
      }
      if (!(this instanceof Embedded) && !wrapingPromise.hasRejectListeners()) {
        wrapingPromise.onReject(self.$__handleReject.bind(self));
      }
      args.push(function () {
        return wrapingPromise.resolve.apply(wrapingPromise, arguments);
      });

      // fire original
      self[newName].apply(self, args);
      return wrapingPromise;
    }, $__original_save=[function (next) {
        // Nested docs have their own presave
        if (this.ownerDocument) {
          return next();
        }

        // Validate
        if (this.schema.options.validateBeforeSave) {
          this.validate(next);
        } else {
          next();
        }
      }], $__original_save=[]
READER-0 RangeError: Maximum call stack size exceeded
    at Function.isArray (native)
    at Object.exports.clone (/home/ubuntu/reader/source/node_modules/winston/lib/winston/common.js:80:15)
    at Object.exports.clone (/home/ubuntu/reader/source/node_modules/winston/lib/winston/common.js:87:61)

@thomasleduc
Copy link

So, is there an update here ?

@d-winter
Copy link

Same problem here...

@skilledDeveloper
Copy link

Probably similar to #862

@mdnorman
Copy link

I have also run into this problem when logging the error object coming from the soap library. This is because the error contains the original request object, and request objects for some reason have circular references. I only see it with the logstash output because it uses the clone function to copy the metadata value into the logstash @fields.

Example line of code:
logger.error('Some error info:', err)

@kevinludwig
Copy link

kevinludwig commented Dec 13, 2016

It's the exact same issue as #862. It occurred with me when I set the option logstash: true which results in a clone here: https://github.com/winstonjs/winston/blob/master/lib/winston/common.js#L198.

One question I have, is why was the cycle method placed at a specific call site, here:
https://github.com/winstonjs/winston/blob/master/lib/winston/common.js#L143

Rather than inside the clone implementation itself? I.e. winston is always trying to clone something that was received from the outside, so the only way to be safe, is to always decycle anything you're going to try to clone.

@shahimclt
Copy link

Any Updates?

I have been constantly checking #862, #474 and #914 for an update. I also have a question posted here which too hasn't gotten any response.

@ngocketit
Copy link

Check #977. Not sure when it's gonna been merged and published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants