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 size exceeded #9

Open
ghost opened this issue Jan 26, 2011 · 2 comments
Open

Maximum call stack size exceeded #9

ghost opened this issue Jan 26, 2011 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 26, 2011

When I used "until" with a 1000 or so iterations, node is saying "Maximum call stack size exceeded". Is there a limit to the number of iterations? My code was working and I think I've coded it properly. FWIW, here is my code.

    async.until(function() {
      return opt.eof && !buf;
    }, function(cb) {
      var delim, match, parts;
      if ((parts = regex.exec(buf))) {
        match = parts[0], delim = parts[1], buf = parts[2];
        switch (opt.delimType) {
          case 'prefix':
            opt.data = prefix + match;
            prefix = delim;
            break;
          case 'suffix':
            opt.data = match + delim;
            break;
          default:
            opt.data = match;
        }
        callback(opt);
        return stopChk(cb);
      } else if (opt.eof) {
        opt.data = prefix + buf;
        callback(opt);
        opt.stop = true;
        return stopChk(cb);
      } else {
        return fs.read(fd, inBuf, 0, opt.bufSize, null, function(err, bytesRead) {
          if (err) {
            return cb(err);
          } else {
            if (bytesRead) {
              buf += inBuf.toString('utf8', 0, bytesRead);
              return cb();
            } else {
              opt.eof = true;
              return fs.close(fd, cb);
            }
          }
        });
      }
    });
    return function(err) {
      if (!opt.stop) {
        opt.err = err;
        return callback(opt);
      }
    };
)

Coffeescript original source ...

async.until \
    -> (opt.eof and not buf),
    (cb) -> 
        if (parts = regex.exec buf)
            [match, delim, buf] = parts
            switch opt.delimType
                when 'prefix' then opt.data = prefix + match; prefix = delim
                when 'suffix' then opt.data = match + delim
                else               opt.data = match
            callback opt
            stopChk cb
        else if opt.eof
            opt.data = prefix + buf
            callback opt
            opt.stop = true
            stopChk cb
        else
            fs.read fd, inBuf, 0, opt.bufSize, null, (err, bytesRead) ->
                if err then cb err
                else
                    if bytesRead
                        buf += inBuf.toString 'utf8', 0, bytesRead
                        cb()
                    else
                        opt.eof = true; fs.close fd, cb
    (err) ->
        if not opt.stop
            opt.err = err
            callback opt
@brenzenb
Copy link

Having a similar issue and would love to know if anyone has an explanation for this

@CrabDude
Copy link

CrabDude commented Mar 7, 2012

Stumbled upon this. There's likely another root cause, but for a band-aid, see increasing the V8 stack size options:

node --stack_size=4096 index.js

https://groups.google.com/group/nodejs-dev/browse_thread/thread/2b206819302ad5c4

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

No branches or pull requests

2 participants