1
  • Node.js Version: v12.13.1.
  • OS: Microsoft Windows 10 Pro, Version: 10.0.18362 Build 18362
  • NPM packages:

    "agenda": "^2.0.2",
    "appmetrics-dash": "^5.0.0",
    "avro-schema-registry": "^1.5.1",
    "avsc": "^5.4.16",
    "await-to-js": "^2.1.1",
    "bluebird": "^3.5.3",
    "body-parser": "^1.18.3",
    "dd-trace": "^0.12.1",
    "debug": "^4.1.0",
    "express": "^4.16.4",
    "express-server-status": "^1.0.3",
    "express-status-monitor": "^1.2.6",
    "json-2-csv": "^3.5.2",
    "kafkajs": "^1.11.0",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "mongodb": "^3.1.8",
    "mongoose": "^5.3.3",
    "mongoose-auto-increment": "^5.0.1",
    "qs": "6.9.0",
    "request": "^2.88.0",
    "request-promise": "^4.2.2",
    "sha256": "^0.2.0",
    "slack-node": "^0.1.8",
    "socket.io": "^2.2.0"
    

I was running only agenda jobs. Almost all jobs are syncing data from other API's and saving all data to MongoDB. Sometimes after some time when I start the project, I get this error:

(node:26128) TimeoutOverflowWarning: 2591699977 does not fit into a 32-bit signed integer. Timeout duration was set to 1. at new Timeout (internal/timers.js:156:15) at setTimeout (timers.js:142:19) at jobProcessing (C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\lib\utils\process-jobs.js:258:7) at C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\lib\utils\process-jobs.js:217:9 at C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\lib\agenda\find-and-lock-next-job.js:81:7 at C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\node_modules\mongodb\lib\utils.js:414:17 at C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\node_modules\mongodb\lib\utils.js:401:11 at ClientSession.endSession (C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\mongodb-core\lib\sessions.js:129:41) at executeCallback (C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\node_modules\mongodb\lib\utils.js:397:17) at handleCallback (C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\node_modules\mongodb\lib\utils.js:128:55) at C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\node_modules\mongodb\lib\operations\collection_ops.js:558:12 at handleCallback (C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\node_modules\mongodb\lib\utils.js:128:55) at C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\agenda\node_modules\mongodb\lib\operations\db_ops.js:516:5 at C:\Users\mailb\OneDrive\Desktop\DST\custom-market\node_modules\mongodb-core\lib\connection\pool.js:532:18 at processTicksAndRejections (internal/process/task_queues.js:75:11)

1 Answers1

0

I ended up to install the "agenda": "2.2.0" version. It reveals that i made a mistake in one of my instance where i didn't throw error, and it make the job infinitely process.

I advise you to try the same and run your server with --trace-warnings.

npm install --save agenda@2.2.0
node --trace-warnings yournodejsapp

Then, just see the logs and it will output where the error happen. Fix the error and you will be good :-)

FYI,

If you look at the agenda source code where the error is happenning.

// If the 'nextRunAt' time is older than the current time, run the job
// Otherwise, setTimeout that gets called at the time of 'nextRunAt'
if (job.attrs.nextRunAt < now) {
  debug('[%s:%s] nextRunAt is in the past, run the job immediately', job.attrs.name, job.attrs._id);
  runOrRetry();
} else {
  const runIn = job.attrs.nextRunAt - now;
  debug('[%s:%s] nextRunAt is in the future, calling setTimeout(%d)', job.attrs.name, job.attrs._id, runIn);
  setTimeout(runOrRetry, runIn);
}

/**
 * Internal method that tries to run a job and if it fails, retries again!
 * @returns {undefined}
 */
async function runOrRetry() {
  if (self._processInterval) {
    const job = jobQueue.pop();
    const jobDefinition = definitions[job.attrs.name];
    if (jobDefinition.concurrency > jobDefinition.running && self._runningJobs.length < self._maxConcurrency) {
      // Get the deadline of when the job is not supposed to go past for locking
      const lockDeadline = new Date(Date.now() - jobDefinition.lockLifetime);

      // This means a job has "expired", as in it has not been "touched" within the lockoutTime
      // Remove from local lock
      // NOTE: Shouldn't we update the 'lockedAt' value in MongoDB so it can be picked up on restart?
      if (job.attrs.lockedAt < lockDeadline) {
        debug('[%s:%s] job lock has expired, freeing it up', job.attrs.name, job.attrs._id);
        self._lockedJobs.splice(self._lockedJobs.indexOf(job), 1);
        jobDefinition.locked--;
        jobProcessing();
        return;
      }

      // Add to local "running" queue
      self._runningJobs.push(job);
      jobDefinition.running++;

      // CALL THE ACTUAL METHOD TO PROCESS THE JOB!!!
      debug('[%s:%s] processing job', job.attrs.name, job.attrs._id);

      job.run()
        .catch(error => [error, job])
        .then(job => processJobResult(...Array.isArray(job) ? job : [null, job])); // eslint-disable-line promise/prefer-await-to-then

      // Re-run the loop to check for more jobs to process (locally)
      jobProcessing();
    } else {
      // Run the job immediately by putting it on the top of the queue
      debug('[%s:%s] concurrency preventing immediate run, pushing job to top of queue', job.attrs.name, job.attrs._id);
      enqueueJobs(job);
    }
  }
}
Chalom.E
  • 617
  • 5
  • 20