Skip to content
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

PM2 requires network connection before startup? #5908

Open
bhallstein opened this issue Oct 25, 2024 · 0 comments
Open

PM2 requires network connection before startup? #5908

bhallstein opened this issue Oct 25, 2024 · 0 comments

Comments

@bhallstein
Copy link

bhallstein commented Oct 25, 2024

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 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: ===============================================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant