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

Cron broken since 3.2.3 ? "PM ID unknown" #4307

Closed
yched opened this issue Jun 5, 2019 · 18 comments
Closed

Cron broken since 3.2.3 ? "PM ID unknown" #4307

yched opened this issue Jun 5, 2019 · 18 comments

Comments

@yched
Copy link

yched commented Jun 5, 2019

Not sure if we're doing something wrong, but PR #3944 broke cron_restart for us :

  • the 1st cron run following the initial pm2 start successfully restarts the app,
  • but all the subsequent runs fail with error PM ID unknown

In more details on a sample setup :

ecosystem.json :

{
  "apps" : [{
    "name"       : "my_app",
    "script"     : "main.js",
    "exec_mode"  : "cluster",
    "autorestart": true,
    "cron_restart" : "* * * * *",
    "log_date_format": "YYYY-MM-DD HH:mm:ss"
  }]
}

main.js :

// Logs on startup
console.log('my_app started');
// Pings every 10s
setInterval(() => console.log('my_app is running'), 10 * 1000);
// Dies after 1m20s (shouldn't happen since pm2 is supposed to restart us every minute)
setTimeout(() => { console.log('my_app will die'); process.exit(0); }, 80 * 1000);

Output of pm2 log :
(can't seem to have PM2 daemon logs include timestamps for some reason ?)

PM2      | App [my_app:0] starting in -cluster mode-      <-- "pm2 start ecosystem.json"
PM2      | App [my_app:0] online
0|my_app | 2019-06-05 13:34:04: my_app started
0|my_app | 2019-06-05 13:34:14: my_app is running
PM2      | [PM2][WORKER] Registering a cron job on: 0
0|my_app | 2019-06-05 13:34:24: my_app is running
0|my_app | 2019-06-05 13:34:34: my_app is running
0|my_app | 2019-06-05 13:34:44: my_app is running
0|my_app | 2019-06-05 13:34:54: my_app is running
PM2      | App [my_app:0] starting in -cluster mode-      <-- 1st cron restart at 13:35:00, works
PM2      | App [my_app:0] online
0|my_app | 2019-06-05 13:35:00: my_app started
_old_0|my_app  | 2019-06-05 13:35:04: my_app is running   <-- apparently the initial process (synced at second 4) keeps running for some time ?
0|my_app       | 2019-06-05 13:35:10: my_app is running   
PM2            | Stopping app:my_app id:_old_0            <-- the initial process is being stopped
PM2            | App name:my_app id:_old_0 disconnected
PM2            | App [my_app:_old_0] exited with code [0] via signal [SIGINT]
PM2            | pid=8462 msg=process killed
0|my_app       | 2019-06-05 13:35:20: my_app is running   
0|my_app       | 2019-06-05 13:35:30: my_app is running
0|my_app       | 2019-06-05 13:35:40: my_app is running
0|my_app       | 2019-06-05 13:35:50: my_app is running
PM2            | Error: PM ID unknown                     <-- 2nd cron restart at 13:36:00, fails
PM2            |     at Object.God.softReloadProcessId ([...]/pm2/lib/God/Reload.js:185:17)
PM2            |     at CronJob.onTick ([...]//pm2/lib/Worker.js:40:13)
PM2            |     at CronJob.fireOnTick ([...]//pm2/node_modules/cron/lib/cron.js:562:23)
PM2            |     at Timeout.callbackWrapper [as _onTimeout] ([...]//pm2/node_modules/cron/lib/cron.js:629:10)
PM2            |     at ontimeout (timers.js:436:11)
PM2            |     at tryOnTimeout (timers.js:300:5)
PM2            |     at listOnTimeout (timers.js:263:5)
PM2            |     at Timer.processTimers (timers.js:223:10)
0|my_app       | 2019-06-05 13:36:00: my_app is running   <-- still running
0|my_app       | 2019-06-05 13:36:10: my_app is running
0|my_app       | 2019-06-05 13:36:20: my_app will die     <-- dies after 80s (= 1min20s after the cron that worked)
PM2            | App name:my_app id:0 disconnected
PM2            | App [my_app:0] exited with code [0] via signal [SIGINT]
PM2            | App [my_app:0] starting in -cluster mode-
PM2            | App [my_app:0] online
0|my_app       | 2019-06-05 13:36:20: my_app started      <-- restarted by autorestart
0|my_app       | 2019-06-05 13:36:30: my_app is running
etc...
- at every round clock minute, cron fails with Error: PM ID unknown
- process naturally dies every 100s, and gets restarted
@yched
Copy link
Author

yched commented Jun 5, 2019

Same setup (main.js / ecosystem.js) with pm2 3.2.2 :
works as expected : app restarts every minute, and never reaches "die after 1m20"

PM2      | App [my_app:0] starting in -cluster mode-
PM2      | App [my_app:0] online
0|my_app | 2019-06-05 14:47:42: my_app started
0|my_app | 2019-06-05 14:47:52: my_app is running
PM2      | Stopping app:my_app id:0                      <-- 1st cron restart
PM2      | App name:my_app id:0 disconnected
PM2      | App [my_app:0] exited with code [0] via signal [SIGINT]
PM2      | pid=16476 msg=process killed
PM2      | App [my_app:0] starting in -cluster mode-
PM2      | App [my_app:0] online
PM2      | Application my_app has been restarted via CRON
0|my_app | 2019-06-05 14:48:00: my_app started
0|my_app | 2019-06-05 14:48:10: my_app is running
0|my_app | 2019-06-05 14:48:20: my_app is running
0|my_app | 2019-06-05 14:48:30: my_app is running
0|my_app | 2019-06-05 14:48:40: my_app is running
0|my_app | 2019-06-05 14:48:50: my_app is running
PM2      | Stopping app:my_app id:0                      <-- 2nd cron restart
PM2      | App name:my_app id:0 disconnected
PM2      | App [my_app:0] exited with code [0] via signal [SIGINT]
PM2      | pid=16496 msg=process killed
PM2      | App [my_app:0] starting in -cluster mode-
PM2      | App [my_app:0] online
PM2      | Application my_app has been restarted via CRON
0|my_app | 2019-06-05 14:49:00: my_app started
0|my_app | 2019-06-05 14:49:10: my_app is running
etc...

@18601673727
Copy link

Similar problem here

@krunalshah68
Copy link

+1

@wong2
Copy link

wong2 commented Jul 12, 2019

same here

@ejames17
Copy link

ejames17 commented Jul 22, 2019

same here.
Im rolling back to 3.2.2

@gnehs
Copy link

gnehs commented Nov 2, 2019

same here

@yahao87
Copy link

yahao87 commented Dec 11, 2019

same here
The same problem occurs with version 3.5.1.

@mirajehossain
Copy link

Same problem here,
Does anyone fix it?

@rcupic
Copy link

rcupic commented Feb 4, 2020

Same problem. I deleted cron job with "pm2 delete {name}", after that it looks like pm2 is still trying to start that process.

@kelleghan1
Copy link

Any solution to this? I am having this issue in a production server

@Allain55
Copy link

Same problem here

@stale
Copy link

stale bot commented Jun 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 19, 2020
@yched
Copy link
Author

yched commented Jun 19, 2020

That is still an issue

@stale stale bot removed the stale label Jun 19, 2020
@stale
Copy link

stale bot commented Jul 19, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 19, 2020
@yched
Copy link
Author

yched commented Jul 19, 2020

seriously ?

@stale stale bot removed the stale label Jul 19, 2020
@goodwillsandy
Copy link

Facing same issue,

--- PM2 report ----------------------------------------------------------------
Date                 : Sat Aug 15 2020 20:24:46 GMT+0000 (Coordinated Universal Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.4.0
node version         : 12.18.3
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : ubuntu
uid                  : 1000
gid                  : 1000
uptime               : 40min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.4.0
node version         : 12.18.3
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/bin/pm2,report
argv0                : node
user                 : ubuntu
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
cpus nb              : 1
freemem              : 114925568
totalmem             : 1026158592
home                 : /home/ubuntu
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬─────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                    │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼─────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ Project2-SchedulerMS    │ default     │ 1.0.0   │ cluster │ 5068     │ 9m     │ 1    │ online    │ 0%       │ 76.8mb   │ ubuntu   │ disabled │
└─────┴─────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/home/ubuntu/.pm2/pm2.log last 20 lines:
PM2        | 2020-08-15T20:12:41: PM2 log: Stopping app:Project2-SchedulerMS id:0
PM2        | 2020-08-15T20:12:41: PM2 log: App name:Project2-SchedulerMS id:0 disconnected
PM2        | 2020-08-15T20:12:41: PM2 log: App [Project2-SchedulerMS:0] exited with code [0] via signal [SIGINT]
PM2        | 2020-08-15T20:12:41: PM2 log: pid=4934 msg=process killed
PM2        | 2020-08-15T20:13:09: PM2 log: [PM2][WORKER] Registering a cron job on: 0
PM2        | 2020-08-15T20:13:09: PM2 log: App [Project2-SchedulerMS:0] starting in -cluster mode-
PM2        | 2020-08-15T20:13:09: PM2 log: App [Project2-SchedulerMS:0] online
PM2        | 2020-08-15T20:15:00: PM2 log: App [Project2-SchedulerMS:0] starting in -cluster mode-
PM2        | 2020-08-15T20:15:00: PM2 log: App [Project2-SchedulerMS:0] online
PM2        | 2020-08-15T20:15:11: PM2 log: Stopping app:Project2-SchedulerMS id:_old_0
PM2        | 2020-08-15T20:15:11: PM2 log: App name:Project2-SchedulerMS id:_old_0 disconnected
PM2        | 2020-08-15T20:15:11: PM2 log: App [Project2-SchedulerMS:_old_0] exited with code [0] via signal [SIGINT]
PM2        | 2020-08-15T20:15:11: PM2 log: pid=5033 msg=process killed
PM2        | 2020-08-15T20:20:00: PM2 error: Error: pm_id _old_0 not available in _old_0
PM2        |     at Object.God.softReloadProcessId (/usr/lib/node_modules/pm2/lib/God/Reload.js:194:17)
PM2        |     at CronJob.onTick (/usr/lib/node_modules/pm2/lib/Worker.js:38:13)
PM2        |     at CronJob.fireOnTick (/usr/lib/node_modules/pm2/node_modules/cron/lib/cron.js:600:23)
PM2        |     at Timeout.callbackWrapper [as _onTimeout] (/usr/lib/node_modules/pm2/node_modules/cron/lib/cron.js:667:10)
PM2        |     at listOnTimeout (internal/timers.js:549:17)
PM2        |     at processTimers (internal/timers.js:492:7)

@goodwillsandy
Copy link

This issue exists here when exec_mode: cluster. If you change to exec_mode: fork it will work.
Keep me posted.

@Unitech
Copy link
Owner

Unitech commented Dec 16, 2020

fixed in pm2@4.5.1:

npm install pm2@latest -g
pm2 update

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