Unitech / Unitech/pm2

increment_var does not increment when restarting/reloading app

Open
#4,502 35 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

The increment_var works correctly only when starting the app for the first time. When restarting or reloading, it doesn't work, so all instances get the same initial value in the env variable.

How could we reproduce this issue?

  • Set a custom env variable, with initial value 1.
  • Set increment_var with the name of the custom env variable.
  • Make sure the exec_mode is cluster.
  • Log the value of the custom env variable in the application.
  • Start the application. Each instance should log a different value.
  • Restart or reload the application. Each instance will log the same initial value.

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Wed Nov 13 2019 12:55:41 GMT+0000 (Coordinated Universal Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.1.2
node version         : 12.13.0
node path            : not found
argv                 : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : stimme
uid                  : 1000
gid                  : 1000
uptime               : 4788min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.1.2
node version         : 12.13.0
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/bin/pm2,report
argv0                : node
user                 : stimme
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
cpus nb              : 2
freemem              : 724017152
totalmem             : 4136554496
home                 : /home/stimme
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬─────────────────────────┬─────────┬─────────┬──────────┬────────┬──────┬──────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name                    │ version │ mode    │ pid      │ uptime │ ↺    │ status   │ cpu      │ mem      │ user     │ watching │
├────┼─────────────────────────┼─────────┼─────────┼──────────┼────────┼──────┼──────────┼──────────┼──────────┼──────────┼──────────┤
│ 3  │ Imaging API             │ 1.0.0   │ cluster │ 19522    │ 2h     │ 2    │ online   │ 0.5%     │ 73.5mb   │ stimme   │ disabled │
│ 4  │ Imaging API             │ 1.0.0   │ cluster │ 19538    │ 2h     │ 2    │ online   │ 0.5%     │ 74.4mb   │ stimme   │ disabled │
│ 5  │ Safir Core API          │ 1.0.0   │ cluster │ 29155    │ 21s    │ 2    │ online   │ 0.5%     │ 139.9mb  │ stimme   │ disabled │
│ 6  │ Safir Core API          │ 1.0.0   │ cluster │ 29172    │ 18s    │ 2    │ online   │ 0.5%     │ 132.8mb  │ stimme   │ disabled │
└────┴─────────────────────────┴─────────┴─────────┴──────────┴────────┴──────┴──────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬───────────────────────────────────────┬────────────────────┬───────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module                                │ version            │ pid   │ status   │ ↺    │ cpu      │ mem      │ user     │
├────┼───────────────────────────────────────┼────────────────────┼───────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 0  │ pm2-logrotate                         │ 2.7.0              │ 1509  │ online   │ 0    │ 0%       │ 78.9mb   │ stimme   │
└────┴───────────────────────────────────────┴────────────────────┴───────┴──────────┴──────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/home/stimme/.pm2/pm2.log last 20 lines:
PM2        | 2019-11-13T12:45:22: PM2 log: App [Safir Core API:_old_5] exited with code [0] via signal [SIGINT]
PM2        | 2019-11-13T12:45:22: PM2 log: pid=28104 msg=process killed
PM2        | 2019-11-13T12:45:22: PM2 log: App [Safir Core API:6] starting in -cluster mode-
PM2        | 2019-11-13T12:45:22: PM2 log: App [Safir Core API:6] online
PM2        | 2019-11-13T12:45:25: PM2 log: Stopping app:Safir Core API id:_old_6
PM2        | 2019-11-13T12:45:25: PM2 log: App name:Safir Core API id:_old_6 disconnected
PM2        | 2019-11-13T12:45:25: PM2 log: App [Safir Core API:_old_6] exited with code [0] via signal [SIGINT]
PM2        | 2019-11-13T12:45:25: PM2 log: pid=28111 msg=process killed
PM2        | 2019-11-13T12:55:19: PM2 log: App [Safir Core API:5] starting in -cluster mode-
PM2        | 2019-11-13T12:55:19: PM2 log: App [Safir Core API:5] online
PM2        | 2019-11-13T12:55:22: PM2 log: -reload- New worker listening
PM2        | 2019-11-13T12:55:22: PM2 log: Stopping app:Safir Core API id:_old_5
PM2        | 2019-11-13T12:55:22: PM2 log: App name:Safir Core API id:_old_5 disconnected
PM2        | 2019-11-13T12:55:22: PM2 log: App [Safir Core API:_old_5] exited with code [0] via signal [SIGINT]
PM2        | 2019-11-13T12:55:22: PM2 log: pid=28362 msg=process killed
PM2        | 2019-11-13T12:55:22: PM2 log: App [Safir Core API:6] starting in -cluster mode-
PM2        | 2019-11-13T12:55:22: PM2 log: App [Safir Core API:6] online
PM2        | 2019-11-13T12:55:25: PM2 log: Stopping app:Safir Core API id:_old_6
PM2        | 2019-11-13T12:55:25: PM2 log: App [Safir Core API:_old_6] exited with code [0] via signal [SIGINT]
PM2        | 2019-11-13T12:55:25: PM2 log: pid=28379 msg=process killed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the listed setup with a custom environment variable, increment_var, and cluster exec_mode, recording values before and after restart or reload. Trace the PM2 cluster reload path that assigns increment_var; done means each worker receives a distinct incremented value both initially and after restart or reload.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.