Unitech / Unitech/pm2

PM2 sometimes shows a running process with pid=0, and is then unable to kill or restart it

Open
#5,331 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

I have a process I'm trying to run (and shutdown gracefully) in PM2 on Windows. I'm using shutdown_with_message in the ecosystem file, and this all works fine -- most of the time. Sometimes, however, when using pm2 restart two things happen: a) the process doesn't appear to receive the message, and b) PM2 never actually kills the process but still tries to start another one. The newly started process will fail because it attempts to bind to a port that is still being held by the old process. This is expected, I'm just trying to find out why the old one neither shuts down gracefully nor gets killed by PM2.

When attempting multiple restarts, I've noticed that pm2 list normally shows a PID for the process. However, it occasionally comes up with a PID of 0 after the restart. It's at this point that the next restart won't work. Presumably PM2 is trying to send the message to, and eventually kill, process 0 instead of the actual one that is running? (The process IS still running as shown in task manager. After killing it there, PM2 is able to start it again.)

Any ideas why the PID would sometimes come up as 0 in pm2 list? Any other troubleshooting steps? Thanks.

(pm2 restart and pm2 reload have the same result.)

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Wed Mar 23 2022 18:04:04 GMT-0700 (Pacific Daylight Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.2.0
node version         : 14.16.0
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\msc\AppData\Roaming\npm\node_modules\pm2\lib\Daemon.js
argv0                : node
user                 : undefined
uid                  : N/A
gid                  : N/A
uptime               : 51min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.2.0
node version         : 14.16.0
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\msc\AppData\Roaming\npm\node_modules\pm2\bin\pm2,report
argv0                : node
user                 : msc
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : win32
type                 : Windows_NT
cpus                 : Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
cpus nb              : 8
freemem              : 4483932160
totalmem             : 16790306816
home                 : C:\Users\msc
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ EngSvr    │ default     │ 4.1.2   │ fork    │ 83856    │ 51m    │ 0    │ online    │ 0%       │ 24.6mb   │ msc… │ disabled │
│ 1   │ Logger    │ default     │ 2.0.1   │ fork    │ 0        │ 0      │ 4    │  │ 0%       │ 0b       │ msc… │ disabled │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
C:\Users\msc\.pm2\pm2.log last 20 lines:
PM2        | 2022-03-23T17:23:36: PM2 log: App [Logger:1] starting in -fork mode-
PM2        | 2022-03-23T17:23:36: PM2 log: App [Logger:1] exited with code [0] via signal [SIGINT]
PM2        | 2022-03-23T17:23:36: PM2 log: App [Logger:1] online
PM2        | 2022-03-23T17:23:50: PM2 log: Process 1 in a stopped status, starting it
PM2        | 2022-03-23T17:23:50: PM2 log: Stopping app:Logger id:1
PM2        | 2022-03-23T17:23:50: PM2 log: pid=91096 msg=failed to kill - retrying in 100ms
PM2        | 2022-03-23T17:23:50: PM2 log: pid=91096 msg=process killed
PM2        | 2022-03-23T17:23:50: PM2 log: App [Logger:1] starting in -fork mode-
PM2        | 2022-03-23T17:23:50: PM2 log: App [Logger:1] online
PM2        | 2022-03-23T17:23:50: PM2 log: App [Logger:1] exited with code [0] via signal [SIGINT]
PM2        | 2022-03-23T17:24:02: PM2 log: Process 1 in a stopped status, starting it
PM2        | 2022-03-23T17:24:02: PM2 log: App [Logger:1] starting in -fork mode-
PM2        | 2022-03-23T17:24:02: PM2 log: App [Logger:1] online
PM2        | 2022-03-23T17:24:02: PM2 log: App [Logger:1] exited with code [1] via signal [SIGINT]
PM2        | 2022-03-23T17:40:18: PM2 log: App [Logger:1] starting in -fork mode-
PM2        | 2022-03-23T17:40:18: PM2 log: App [Logger:1] online
PM2        | 2022-03-23T17:40:19: PM2 log: App [Logger:1] exited with code [1] via signal [SIGINT]
PM2        | 2022-03-23T17:41:19: PM2 log: Stopping app:Logger id:1
PM2        | 2022-03-23T17:41:19: PM2 error: app=Logger id=1 does not have a pid
PM2        | 2022-03-23T17:41:31: PM2 log: App [Logger:1] exited with code [1] via signal [SIGINT]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Windows PM2 report and daemon logs, especially the restart entries showing pid=0 and “does not have a pid.” Reproduce repeated pm2 restart or pm2 reload for an ecosystem process using shutdown_with_message, then trace how the process PID is recorded and used. Done means the old process is handled correctly and a restart does not leave a running process represented by pid=0.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.