Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.53k stars 2.62k forks source link

stop_exit_codes not working #5601

Open lumos42 opened 1 year ago

lumos42 commented 1 year ago

What's going wrong?

I have the following config for an application

{
        name: "indexer",
        script: "./indexer/indexer.js",
        error_file: "./logs/indexer.out.log",
        out_file: "./logs/indexer.out.log",
        log_date_format: "DD-MM-YY HH:mm:ss",
        instance_var: 'INSTANCE_ID',
        cron_restart: "*/5 * * * *",
        autorestart: true,
        stop_exit_codes: [0]
}

Indexer only takes 10 seconds to run. I want it to run once every 5 minutes, but it should start again in case the system reboots and resurrect is called. The config looks right as per the docs, but stop_exit_codes = [0] doesn't seem to work. In the pm2 logs I can see that indexer indeed exits with code 0, but still it keeps running indexer every 3-4 seconds. This is the output of pm2 logs:

PM2        | App [indexer:5] exited with code [0] via signal [SIGINT]
PM2        | App [indexer:5] starting in -fork mode-
PM2        | App [indexer:5] online
5|indexer  | 10-05-23 17:27:55: hello
PM2        | App [indexer:5] exited with code [0] via signal [SIGINT]
PM2        | App [indexer:5] starting in -fork mode-
PM2        | App [indexer:5] online
5|indexer  | 10-05-23 17:27:58: hello

How could we reproduce this issue?

  1. Use the config I provided and run the application once
  2. pm2 save
  3. pm2 kill
  4. pm2 resurrect

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Wed May 10 2023 17:33:46 GMT+0530 (India Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.3.0
node version         : 16.16.0
node path            : /usr/local/bin/pm2
argv                 : /usr/local/bin/node,/usr/local/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : shubham
uid                  : 501
gid                  : 20
uptime               : 81min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.3.0
node version         : 16.16.0
node path            : /usr/local/bin/pm2
argv                 : /usr/local/bin/node,/usr/local/bin/pm2,report
argv0                : node
user                 : shubham
uid                  : 501
gid                  : 20
===============================================================================
--- System info --------------------------------------------
arch                 : arm64
platform             : darwin
type                 : Darwin
cpus                 : Apple M1 Pro
cpus nb              : 8
freemem              : 81494016
totalmem             : 17179869184
home                 : /Users/shubham
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 5  │ indexer            │ fork     │ 1527 │ online    │ 0%       │ 86.7mb   │
│ 6  │ listener           │ fork     │ 0    │ online    │ 0.2%     │ 46.3mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
Module
┌────┬────────────────────┬──────────┬──────────┬──────────┐
│ id │ name               │ status   │ cpu      │ mem      │
├────┼────────────────────┼──────────┼──────────┼──────────┤
│ 0  │ pm2-slack          │ online   │ 0.1%     │ 36.5mb   │
└────┴────────────────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/Users/shubham/.pm2/pm2.log last 20 lines:
PM2        | 2023-05-10T17:33:27: PM2 log: App [indexer:5] starting in -fork mode-
PM2        | 2023-05-10T17:33:27: PM2 log: App [indexer:5] online
PM2        | 2023-05-10T17:33:30: PM2 log: App [indexer:5] exited with code [0] via signal [SIGINT]
PM2        | 2023-05-10T17:33:30: PM2 log: App [indexer:5] starting in -fork mode-
PM2        | 2023-05-10T17:33:30: PM2 log: App [indexer:5] online
PM2        | 2023-05-10T17:33:33: PM2 log: App [indexer:5] exited with code [0] via signal [SIGINT]
PM2        | 2023-05-10T17:33:33: PM2 log: App [indexer:5] starting in -fork mode-
PM2        | 2023-05-10T17:33:33: PM2 log: App [indexer:5] online
PM2        | 2023-05-10T17:33:36: PM2 log: App [indexer:5] exited with code [0] via signal [SIGINT]
PM2        | 2023-05-10T17:33:36: PM2 log: App [indexer:5] starting in -fork mode-
PM2        | 2023-05-10T17:33:36: PM2 log: App [indexer:5] online
PM2        | 2023-05-10T17:33:39: PM2 log: App [indexer:5] exited with code [0] via signal [SIGINT]
PM2        | 2023-05-10T17:33:39: PM2 log: App [indexer:5] starting in -fork mode-
PM2        | 2023-05-10T17:33:39: PM2 log: App [indexer:5] online
PM2        | 2023-05-10T17:33:42: PM2 log: App [indexer:5] exited with code [0] via signal [SIGINT]
PM2        | 2023-05-10T17:33:42: PM2 log: App [indexer:5] starting in -fork mode-
PM2        | 2023-05-10T17:33:42: PM2 log: App [indexer:5] online
PM2        | 2023-05-10T17:33:46: PM2 log: App [indexer:5] exited with code [0] via signal [SIGINT]
PM2        | 2023-05-10T17:33:46: PM2 log: App [indexer:5] starting in -fork mode-
PM2        | 2023-05-10T17:33:46: PM2 log: App [indexer:5] online
Erickud commented 1 year ago

See #5208

lumos42 commented 1 year ago

This is a different issue where I don't get an error, but at the same time it fails to stop the restarting even after exit status 0

drag0n-app commented 10 months ago

same issue on 5.3.0

drag0n-app commented 10 months ago

same issue on 5.3.0

install the dev version resolve this problem npm install -g github:Unitech/pm2#development

jayzun commented 10 months ago

same issue on 5.3.0

secondfry commented 8 months ago

It does not work with stop_exit_codes: [0], and works with any other custom exit code, i.e. stop_exit_codes: [42],. Tests for this feature in the repo check for stop_exit_codes: [12, 42], so they don't reach problem with exit code 0 (I guess).

UPD: For strange unknown reason, setting stopExitCodes: [93],, changing app, then setting stopExitCodes: [0], and changing app again made it work. Maybe configs are cached?..