You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using pm2 scale <app_name> -1 to reduce the number of instances for a PM2-managed application, an error occurs because the -1 is being treated as an option, not as a valid argument to decrease the number of instances.
Root Cause
The issue arises because commander.js, which PM2 uses for argument parsing, treats -1 as an option due to the leading hyphen (-), resulting in the error. As seen in commander.js documentation, the hyphen (-) is reserved for option flags, causing unintended behavior when attempting to pass a negative number to scale down instances.
Suggested Improvement
To resolve this, it would be ideal to:
Support the -1 argument as a valid input for reducing the number of instances.
Consider using a different symbol (such as ~ or another syntax) to indicate a relative scale change, e.g., pm2 scale <app_name> ~1 to decrease by one instance.
How could we reproduce this issue?
Start an application using PM2: pm2 start --name <app_name> app.js
Attempt to scale the application down by 1 instance using: pm2 scale <app_name> -1
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Wed Dec 25 2024 10:31:22 GMT+0800 (台北標準時間)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.4.3
node version : 22.11.0
node path : not found
argv : C:\Program Files\nodejs\node.exe,C:\Program Files (x86)\nvm\v22.11.0\node_modules\pm2\lib\Daemon.js
argv0 : node
user : undefined
uid : N/A
gid : N/A
uptime : 33min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.4.3
node version : 22.11.0
node path : not found
argv : C:\Program Files\nodejs\node.exe,C:\Program Files\nodejs\node_modules\pm2\bin\pm2,report
argv0 : C:\Program Files\nodejs\node.exe
user : user
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : win32
type : Windows_NT
cpus : 12th Gen Intel(R) Core(TM) i7-1260P
cpus nb : 16
freemem : 9051037696
totalmem : 25358680064
home : C:\Users\user
What's going wrong?
When using pm2 scale <app_name> -1 to reduce the number of instances for a PM2-managed application, an error occurs because the -1 is being treated as an option, not as a valid argument to decrease the number of instances.
Root Cause
The issue arises because commander.js, which PM2 uses for argument parsing, treats -1 as an option due to the leading hyphen (-), resulting in the error. As seen in commander.js documentation, the hyphen (-) is reserved for option flags, causing unintended behavior when attempting to pass a negative number to scale down instances.
Suggested Improvement
To resolve this, it would be ideal to:
How could we reproduce this issue?
Start an application using PM2:
pm2 start --name <app_name> app.js
Attempt to scale the application down by 1 instance using:
pm2 scale <app_name> -1
Supporting information
References
commander.js documentation (v2.15.1)
PM2 code that handles scaling
pm2/lib/API.js
Lines 1828 to 1835 in e3a327f
The text was updated successfully, but these errors were encountered: