Multiple executions (one too many) when using two apps in cluster mode
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?
When running two apps with basic setInterval, one of them runs with two process/threads.

It's probably mine fault, I'm not that experience with pm2, perhaps this is correct behavior for the cluster mode?
How could we reproduce this issue?
Repository to demonstrate the issue is available here: https://github.com/sondreb/pm2-issue
Supporting information
OS: Windows 11
Node.js: v14.17.6
$ pm2 report
--- PM2 report ----------------------------------------------------------------
Date : Sun Oct 03 2021 21:10:54 GMT+0200 (Central European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.1.2
node version : 14.17.6
node path : not found
argv : C:\Program Files\nodejs\node.exe,C:\Users\USER\AppData\Roaming\npm\node_modules\pm2\lib\Daemon.js
argv0 : node
user : undefined
uid : N/A
gid : N/A
uptime : 1min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.1.2
node version : 14.17.6
node path : not found
argv : C:\Program Files\nodejs\node.exe,C:\Users\USER\AppData\Roaming\npm\node_modules\pm2\bin\pm2,report
argv0 : node
user : USER
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : win32
type : Windows_NT
cpus : Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
cpus nb : 8
freemem : 18051014656
totalmem : 34294517760
home : C:\Users\USER
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬─────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼─────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1 │ api │ default │ 0.0.9 │ cluster │ 13212 │ 68s │ 1 │ online │ 0% │ 33.7mb │ USER │ disabled │
│ 0 │ sync │ default │ 0.0.9 │ cluster │ 42108 │ 68s │ 1 │ online │ 0% │ 33.6mb │ USER │ disabled │
└─────┴─────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
C:\Users\USER\.pm2\pm2.log last 20 lines:
PM2 | 2021-10-03T21:09:41: PM2 log: Process dump file : C:\Users\USER\.pm2\dump.pm2
PM2 | 2021-10-03T21:09:41: PM2 log: Concurrent actions : 2
PM2 | 2021-10-03T21:09:41: PM2 log: SIGTERM timeout : 1600
PM2 | 2021-10-03T21:09:41: PM2 log: ===============================================================================
PM2 | 2021-10-03T21:09:41: PM2 log: App [sync:0] starting in -cluster mode-
PM2 | 2021-10-03T21:09:41: PM2 log: App [api:1] starting in -cluster mode-
PM2 | 2021-10-03T21:09:41: PM2 log: App [sync:0] online
PM2 | 2021-10-03T21:09:41: PM2 log: App [api:1] online
PM2 | 2021-10-03T21:09:45: PM2 log: Stopping app:sync id:0
PM2 | 2021-10-03T21:09:45: PM2 log: Stopping app:api id:1
PM2 | 2021-10-03T21:09:45: PM2 log: App name:sync id:0 disconnected
PM2 | 2021-10-03T21:09:45: PM2 log: App name:api id:1 disconnected
PM2 | 2021-10-03T21:09:45: PM2 log: App [sync:0] exited with code [1] via signal [SIGINT]
PM2 | 2021-10-03T21:09:45: PM2 log: App [api:1] exited with code [1] via signal [SIGINT]
PM2 | 2021-10-03T21:09:45: PM2 log: pid=39988 msg=process killed
PM2 | 2021-10-03T21:09:45: PM2 log: App [sync:0] starting in -cluster mode-
PM2 | 2021-10-03T21:09:45: PM2 log: pid=25516 msg=process killed
PM2 | 2021-10-03T21:09:45: PM2 log: App [api:1] starting in -cluster mode-
PM2 | 2021-10-03T21:09:45: PM2 log: App [sync:0] online
PM2 | 2021-10-03T21:09:45: PM2 log: App [api:1] online
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository and run its two apps under PM2 5.1.2 in cluster mode on the reported Node.js and Windows environment. Compare the interval execution count with the PM2 report and daemon logs, then establish whether the extra execution is expected or a defect; done means the behavior is explained and, if defective, the reproduction no longer shows it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100