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

PM2 global error caught - Something went wrong. cron reached maximum iterations #5183

Closed
mararrdeveloper opened this issue Sep 24, 2021 · 2 comments

Comments

@mararrdeveloper
Copy link
Contributor

mararrdeveloper commented Sep 24, 2021

By time to time, PM2 crashes apparently because of a crash on the cron module. It looks like that the github page of the node-cron module is plenty of complaints about this error (https://github.com/kelektiv/node-cron/issues?page=2&q=cron+reached+maximum+iterations) but no fixes have been provided. Is it time to change the dependency to something else?

Here the error:

--- PM2 global error caught ---------------------------------------------------
Time                 : Wed Sep 22 2021 18:00:23 GMT+0000 (Coordinated Universal Time)
Something went wrong. cron reached maximum iterations.
#011#011#011#011#011#011Please open an  issue (https://github.com/kelektiv/node-cron/issues/new) and provide the following string
 #011#011#011#011#011#011Time Zone: "" - Cron String: 0 0 0,3,6,9,12,15,18,21 * * * - UTC offset: +00:00 - current Date: Wed Sep 22 2021 18:00:14 GMT+0000
Error: Something went wrong. cron reached maximum iterations.
#011#011#011#011#011#011Please open an  issue (https://github.com/kelektiv/node-cron/issues/new) and provide the following string
#011#011#011#011#011#011Time Zone: "" - Cron String: 0 0 0,3,6,9,12,15,18,21 * * * - UTC offset: +00:00 - current Date: Wed Sep 22 2021 18:00:14 GMT+0000
    at CronTime._getNextDateFrom (/opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/node_modules/cron/lib/cron.js:235:12)
    at CronTime.sendAt (/opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/node_modules/cron/lib/cron.js:156:17)
    at CronTime.getTimeout (/opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/node_modules/cron/lib/cron.js:175:29)
    at CronJob.start (/opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/node_modules/cron/lib/cron.js:613:31)
    at Timeout.callbackWrapper [as _onTimeout] (/opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/node_modules/cron/lib/cron.js:665:29)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)

Here the configuration of pm2:

module.exports = {
  apps: [
    {
      name: 'app1',
      script: 'Queues/app1.js',
      instances: 1,
      exec_mode: 'fork',
      //Every 30 minutes
      cron_restart: '*/30 * * * *',
      watch: false,
      autorestart: false
    },

    {
      name: 'app2',
      script: 'Queues/app2.js',
      instances: 1,
      exec_mode: 'fork',
      //Every 3 hours (minute 0)
      cron_restart: '0 */3 * * *',
      watch: false,
      autorestart: false
    },

    {
      name: 'app3',
      script: 'Queues/app3.js',
      instances: 1,
      exec_mode: 'fork',
      //At 3.00
      cron_restart: '0 3 * * *',
      watch: false,
      autorestart: false
    },

    {
      name: 'app4',
      script: 'Queues/app4.js',
      instances: 1,
      exec_mode: 'fork',
      watch: false,
      autorestart: true,
      restart_delay: 10 * 60 * 1000, //10 minutes
      kill_timeout: 5 * 60 * 1000 //5 minutes to kill the the process
    },

    {
      name: 'app5',
      script: 'Queues/app5.js',
      instances: 1,
      exec_mode: 'fork',
      //Every 3 hours (minute 15)
      cron_restart: '15 */3 * * *',
      watch: false,
      autorestart: false,
      kill_timeout: 5 * 60 * 1000 //5 minutes to kill the the process
    },

    {
      name: 'app6',
      script: 'Queues/app6.js',
      instances: 1,
      exec_mode: 'fork',
      watch: false,
      autorestart: false,
      kill_timeout: 5 * 60 * 1000, //5 minutes to kill the the process
      //At 3.15
      cron_restart: '15 3 * * *'
    }
  ]
}

Here the pm2 report

--- PM2 report ----------------------------------------------------------------
Date                 : Fri Sep 24 2021 19:55:26 GMT+0000 (Coordinated Universal Time)
===============================================================================
--- Daemon -------------------------------------------------
/opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/lib/API/Extra.js:113
      fmt.field('pm2d version', report.pm2_version);
                                       ^

TypeError: Cannot read property 'pm2_version' of undefined
    at /opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/lib/API/Extra.js:113:40
    at /opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/lib/Client.js:531:18
    at /opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/lib/Client.js:107:21
    at ChildProcess.onError (/opt/elasticbeanstalk/node-install/node-v14.17.5-linux-x64/lib/node_modules/pm2/lib/Client.js:269:17)
    at Object.onceWrapper (events.js:520:26)
    at ChildProcess.emit (events.js:400:28)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:467:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
    at runNextTicks (internal/process/task_queues.js:64:3)
@Hexagon
Copy link

Hexagon commented Feb 4, 2022

The cron library is more or less broken and abandoned. I would suggest you to have a look at github.com/hexagon/croner. Pay special attention to the section "Why another JavaScript cron implementation?"

@Unitech
Copy link
Owner

Unitech commented Feb 17, 2022

Published on 5.2.0

npm install pm2@latest -g
pm2 update

@Unitech Unitech closed this as completed Feb 17, 2022
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

3 participants