Skip to content

Maximum call stack size exceeded #9

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions