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
In dev mode, our app is run on macbooks, where our cli uses pm2 to start up a few separate node apps.
When pm2 is run and the machine's network is up (connected to wifi, etc.) everything is fine. However, if the machine's network is down, pm2 stalls for a long time, perhaps indefinitely.
In fact pm2 stalls for a long time when the network is down even when running commands that do not start up any services, e.g. pm2 --help on my last test stalled for 7 minutes showing a spinner before finally outputting the usual help text.
I read about the --wait-ip option and found https://github.com/Unitech/pm2/blob/master/lib/templates/init-scripts/systemd-online.tpl which includes Wants=network-online.target and WantedBy=multi-user.target network-online.target, and without --wait-ip it appears that https://github.com/Unitech/pm2/blob/master/lib/templates/init-scripts/systemd.tpl is used instead, which includes After=network.target. (Noting these are a systemd scripts but assume the behaviour on mac would be similar.) This suggests that pm2 does indeed wait for a network connection, perhaps? Is there a concise way to disable this, which would be especially useful on dev machines when a network connection may not be available? (e.g. this means we cannot work on our app on plane journeys, for instance.)
How could we reproduce this issue?
Create a simple node service (could probably be an empty js file since the stalling behaviour occurs before the service is started)
Run pm2 start my-file.js with the network not connected
Observe pm2 stalling for a long time — waiting for a network connection that never comes?
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Fri Oct 25 2024 12:52:27 GMT+0100 (British Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.4.2
node version : 22.8.0
node path : /Users/ben/.npm/_npx/5f7878ce38f1eb13/node_modules/.bin/pm2
argv : /opt/homebrew/Cellar/node/22.8.0/bin/node,/Users/ben/.npm/_npx/5f7878ce38f1eb13/node_modules/pm2/lib/Daemon.js
argv0 : node
user : ben
uid : 501
gid : 20
uptime : 28min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.4.2
node version : 22.8.0
node path : /Users/ben/.npm/_npx/5f7878ce38f1eb13/node_modules/.bin/pm2
argv : /opt/homebrew/Cellar/node/22.8.0/bin/node,/Users/ben/.npm/_npx/5f7878ce38f1eb13/node_modules/.bin/pm2,report
argv0 : node
user : ben
uid : 501
gid : 20
===============================================================================
--- System info --------------------------------------------
arch : arm64
platform : darwin
type : Darwin
cpus : Apple M1
cpus nb : 8
freemem : 68501504
totalmem : 8589934592
home : /Users/ben
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
└────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. App web.staging-temp.wombat.sh.e07969 differs. Type 'pm2 save' to synchronize.
===============================================================================
--- Daemon logs --------------------------------------------
/Users/ben/.pm2/pm2.log last 20 lines:
PM2 | 2024-10-25T12:22:28: PM2 log: Concurrent actions : 2
PM2 | 2024-10-25T12:22:28: PM2 log: SIGTERM timeout : 1600
PM2 | 2024-10-25T12:22:28: PM2 log: ===============================================================================
PM2 | 2024-10-25T12:22:28: PM2 log: PM2 successfully stopped
PM2 | 2024-10-25T12:23:37: PM2 log: ===============================================================================
PM2 | 2024-10-25T12:23:37: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2 | 2024-10-25T12:23:37: PM2 log: Time : Fri Oct 25 2024 12:23:37 GMT+0100 (British Summer Time)
PM2 | 2024-10-25T12:23:37: PM2 log: PM2 version : 5.4.2
PM2 | 2024-10-25T12:23:37: PM2 log: Node.js version : 22.8.0
PM2 | 2024-10-25T12:23:37: PM2 log: Current arch : arm64
PM2 | 2024-10-25T12:23:37: PM2 log: PM2 home : /Users/ben/.pm2
PM2 | 2024-10-25T12:23:37: PM2 log: PM2 PID file : /Users/ben/.pm2/pm2.pid
PM2 | 2024-10-25T12:23:37: PM2 log: RPC socket file : /Users/ben/.pm2/rpc.sock
PM2 | 2024-10-25T12:23:37: PM2 log: BUS socket file : /Users/ben/.pm2/pub.sock
PM2 | 2024-10-25T12:23:37: PM2 log: Application log path : /Users/ben/.pm2/logs
PM2 | 2024-10-25T12:23:37: PM2 log: Worker Interval : 30000
PM2 | 2024-10-25T12:23:37: PM2 log: Process dump file : /Users/ben/.pm2/dump.pm2
PM2 | 2024-10-25T12:23:37: PM2 log: Concurrent actions : 2
PM2 | 2024-10-25T12:23:37: PM2 log: SIGTERM timeout : 1600
PM2 | 2024-10-25T12:23:37: PM2 log: ===============================================================================
The text was updated successfully, but these errors were encountered:
What's going wrong?
In dev mode, our app is run on macbooks, where our cli uses pm2 to start up a few separate node apps.
When pm2 is run and the machine's network is up (connected to wifi, etc.) everything is fine. However, if the machine's network is down, pm2 stalls for a long time, perhaps indefinitely.
In fact pm2 stalls for a long time when the network is down even when running commands that do not start up any services, e.g.
pm2 --help
on my last test stalled for 7 minutes showing a spinner before finally outputting the usual help text.I read about the
--wait-ip
option and found https://github.com/Unitech/pm2/blob/master/lib/templates/init-scripts/systemd-online.tpl which includesWants=network-online.target
andWantedBy=multi-user.target network-online.target
, and without--wait-ip
it appears that https://github.com/Unitech/pm2/blob/master/lib/templates/init-scripts/systemd.tpl is used instead, which includesAfter=network.target
. (Noting these are a systemd scripts but assume the behaviour on mac would be similar.) This suggests that pm2 does indeed wait for a network connection, perhaps? Is there a concise way to disable this, which would be especially useful on dev machines when a network connection may not be available? (e.g. this means we cannot work on our app on plane journeys, for instance.)How could we reproduce this issue?
pm2 start my-file.js
with the network not connectedSupporting information
The text was updated successfully, but these errors were encountered: