-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
increment_var does not increment when restarting/reloading app #4502
Comments
I seem to have the same issue, but when running in fork mode. My PM2 version is 4.1.2. I'm using a file called
The index.js has a line
After doing
It shows that the port numbers are correct for the first start, but on both manual and subsequent automatic restarts (the app crashes since after logging it tries to listen on that port and that doesn't work when all 4 instances try listening on the same port) all instances get the same port - 6060. |
Can someone help with this? It's still happening in PM2 version 4.2.0 |
Still happening in version 4.2.1 |
same issue, im using 4.2.1 in fork mode. |
Same issue with version 4.2.3. |
I'm also having the same issue and still using the same workaround. Very nasty! |
Same for me :( |
Same here! |
me too😔 |
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. |
Ping to prevent this issue from being closed for inactivity!
…On Sat, May 23, 2020, 18:56 stale[bot] ***@***.***> wrote:
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.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4502 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AF6N47QSIC6Z6FVISSRNDS3RS753TANCNFSM4JM3BSLQ>
.
|
😑 |
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. |
😒 |
still the same ??? |
Yes, now I must |
Unfurtunately yes |
same problem... |
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. |
Ping to prevent this issue from being closed for inactivity |
Ping this issue. Happens in fork mode.
const path = require('path');
const os = require('os');
const packageJson = require(path.resolve(__dirname, 'package.json'));
const PORT = 33010;
const WARPAPP_PM_FORK_PORT_START = PORT;
const WARPAPP_PM_FORK_PORT_COUNT = Math.max(1, os.cpus().length - 1);
module.exports = {
apps: [
{
name: packageJson.name,
script: path.resolve(__dirname, 'app/app.js'),
autorestart: true,
watch: false,
max_memory_restart: '128M',
instance_var: 'WARPAPP_PM_FORK_ID',
wait_ready: true,
listen_timeout: 3000,
kill_timeout: 3000,
instances: WARPAPP_PM_FORK_PORT_COUNT,
exec_mode: 'fork',
increment_var: 'PORT',
env: {
DEBUG: 'warp*',
NODE_ENV: 'development',
WARP_FQDN_APP: 'xxx.devserver.tld',
WARP_FQDN_CDN: 'xxx.devcdn.tld',
WARP_VERSION_CDN_PRECOMPILED: 'vp001',
PORT,
WARPAPP_PM_FORK_PORT_START,
WARPAPP_PM_FORK_PORT_COUNT
},
env_development: {
DEBUG: 'warp*',
NODE_ENV: 'development',
WARP_FQDN_APP: 'xxx.devserver.tld',
WARP_FQDN_CDN: 'xxx.devcdn.tld',
WARP_VERSION_CDN_PRECOMPILED: 'vp001',
PORT,
WARPAPP_PM_FORK_PORT_START,
WARPAPP_PM_FORK_PORT_COUNT
},
env_testing: {
NODE_ENV: 'testing',
WARP_FQDN_APP: 'xxx.devserver.tld',
WARP_FQDN_CDN: 'xxx.devcdn.tld',
WARP_VERSION_CDN_PRECOMPILED: 'vp001',
PORT,
WARPAPP_PM_FORK_PORT_START,
WARPAPP_PM_FORK_PORT_COUNT
},
env_staging: {
NODE_ENV: 'production',
WARP_FQDN_APP: 'stage.finalapp.tld',
WARP_FQDN_CDN: 'xxxxxx.cloudfront.net',
WARP_VERSION_CDN_PRECOMPILED: 'vp001',
PORT,
WARPAPP_PM_FORK_PORT_START,
WARPAPP_PM_FORK_PORT_COUNT
},
env_production: {
NODE_ENV: 'production',
WARP_FQDN_APP: 'www.finalapp.tld',
WARP_FQDN_CDN: 'xxxxxx.cloudfront.net',
WARP_VERSION_CDN_PRECOMPILED: 'vp001',
PORT,
WARPAPP_PM_FORK_PORT_START,
WARPAPP_PM_FORK_PORT_COUNT
},
error_file: path.join(__dirname, '../../logs/pm2/pm2-err.log'),
out_file: path.join(__dirname, '../../logs/pm2/pm2-out.log'),
log_file: path.join(__dirname, '../../logs/pm2/pm2-combined.log'),
time: true
}
]
}; Note that
// do not consume port number directly from env
// const PORT = normalizeEnvNumber(process.env.PORT || 33000);
// instead ->
const WARPAPP_PM_FORK_ID = normalizeEnvNumber(process.env.WARPAPP_PM_FORK_ID || 0);
const WARPAPP_PM_FORK_PORT_START = normalizeEnvNumber(process.env.WARPAPP_PM_FORK_PORT_START || 0);
const WARPAPP_PM_FORK_PORT_COUNT = normalizeEnvNumber(process.env.WARPAPP_PM_FORK_PORT_COUNT || 0);
// set PORT from PORT_START plus FORK_ID
const PORT = WARPAPP_PM_FORK_PORT_START + WARPAPP_PM_FORK_ID; |
I confirm the existence of this problem. It can't be solved for more than a year. Fortunately, there is a simple logical workaround that does not require restarting the process:
This solution is probably the most logical, because knowing the initial port number and the current instance, we can always find out the current increment offset. |
I cant reproduce in fork mode on PM2 4.5.6 |
I just updated to 5.1.1 and the issue is fixed! |
it works after kill pm2 |
@NinoSkopac I'm using 5.2.0 and I still have this issue. |
this is a serious bug that needs to be fixed which already affected our long running service multiple times, just found this issue that lived for almost 3 years. I really regret using pm2 in the first place |
Seems like @Unitech is on lifelong vacation. This bug is killing us. |
Almost 4 years later .... still same thing. |
it is really a tier-0 bug |
What’s a tier-0 bug
…On Thu, Nov 2, 2023 at 04:28 Boning ***@***.***> wrote:
it is really a tier-0 bug
—
Reply to this email directly, view it on GitHub
<#4502 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANTPNFOTRRE5NLBTD3WWITYCK5G7AVCNFSM4JM3BSL2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZYHE3TCMZYGI3A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
5.2.2 The problem is still found. |
Solved #5715 |
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?
increment_var
with the name of the custom env variable.exec_mode
iscluster
.Supporting information
The text was updated successfully, but these errors were encountered: