Unitech / Unitech/pm2

PM2: process.on('message') prevent process to be stopped.

Open
#4,848 1 comment 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

What's going wrong?

process.on('message') prevent process to be stopped even when no more operations are pending.

How could we reproduce this issue?

// index.js
console.log('Log 1');
process.on('message', () => {});
console.log('Log 2');

PM2 Start

pm2 start index.js --no-autorestart
Output
[PM2] Starting C:\Users\<USERNAME>\Desktop\exp-pm2\index.js in fork_mode (1 instance)
[PM2] Done.
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │                         
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ index              │ fork     │ 0    │ online    │ 10.8%    │ 25.6mb   │                         
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘

PM2 Logs

pm2 logs
Output
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
PM2      | App [index:0] starting in -fork mode-
PM2      | App [index:0] online
0|index  | Log 1
0|index  | Log 2

No Exit in HERE.

PM2 List

pm2 list
Output
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ index              │ fork     │ 0    │ online    │ 0%       │ 22.7mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘

Still Online.

Supporting information

$ pm2 report
Output
--- PM2 report ----------------------------------------------------------------
Date                 : Tue Sep 08 2020 09:20:51 GMT+0200 (Eastern European Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.4.1
node version         : 12.14.0
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\<USERNAME>\AppData\Roaming\npm\node_modules\pm2\lib\Daemon.js
argv0                : node
user                 : undefined
uid                  : N/A
gid                  : N/A
uptime               : 1403min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.4.1
node version         : 12.14.0
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\<USERNAME>\AppData\Roaming\npm\node_modules\pm2\bin\pm2,report
argv0                : C:\Program Files\nodejs\node.exe
user                 : <USERNAME>
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : win32
type                 : Windows_NT
cpus                 : Intel(R) Xeon(R) CPU           X5680  @ 3.33GHz
cpus nb              : 6
freemem              : 8952524800
totalmem             : 17177333760
home                 : C:\Users\<USERNAME>
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ index              │ fork     │ 0    │ online    │ 0%       │ 22.2mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
===============================================================================

Of course we can us removeListener to stop listening to message event, but I guess it's not a good solution.

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 provided index.js reproduction and run it through pm2 start index.js --no-autorestart, then inspect the PM2 process-management entry points involved in stopping forked applications. Done means a process that only registers process.on('message') exits naturally and PM2 no longer reports it as online.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.