"Failed to kill" when using Stop via JavaScript API
Open
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?
If I run pm2 stop <task> on the command line it works fine. However, with the JavaScript function pm2.stop(task) I get failed to kill, eventually it kills everything instead which is far from ideal because that stops my server!
How could we reproduce this issue?
Use pm2.stop().
Some code:
const start = function (task) {
log.out('INFO: ' + task + ' start request received');
if (isRunning(task) === true) {
log.out('INFO: ' + task + ' already in progress.');
return 'INFO: ' + task + ' already in progress.';
}
try {
if (tasks[task]) {
tasks[task].running = true
} else {
tasks[task] = {running: true}
}
pm2.start({
name: task,
script: `npm run ${task}`,
autorestart : false
}, (err, apps) => {
pm2.disconnect()
if (err) { throw err }
})
} catch (err) {
tasks[task].running = false;
log.out('ERR: ' + task + ' error ' + err);
}
log.out('INFO: ' + task + ' started');
return 'INFO: ' + task + ' started'
}
const stop = function (task) {
try {
if (isRunning(task) === true) {
pm2.stop(task)
tasks[task].running = false;
}
return true;
} catch (error) {
return `Failed to stop task. Error: ${error}`
}
Supporting information
PM2 | pid=5394 msg=failed to kill - retrying in 100ms
PM2 | pid=5394 msg=failed to kill - retrying in 100ms
PM2 | pid=5394 msg=failed to kill - retrying in 100ms
PM2 | pid=5394 msg=failed to kill - retrying in 100ms
PM2 | pid=5394 msg=failed to kill - retrying in 100ms
PM2 | pid=5394 msg=failed to kill - retrying in 100ms
PM2 | pid=5394 msg=failed to kill - retrying in 100ms
PM2 | pid=5394 msg=failed to kill - retrying in 100ms
PM2 | pid=5394 msg=failed to kill - retrying in 100ms
PM2 | Process with pid 5394 still alive after 1600ms, sending it SIGKILL now...
PM2 | App [wallet-web-all:1] exited with code [0] via signal [SIGKILL]
PM2 | pid=5394 msg=process killed
--- PM2 report ----------------------------------------------------------------
Date : Fri Jul 16 2021 13:05:13 GMT+0100 (British Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.1.0
node version : 14.15.5
node path : /usr/local/bin/pm2
argv : /usr/local/bin/node,/usr/local/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : georgeashton
uid : 503
gid : 20
uptime : 12min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.1.0
node version : 14.15.5
node path : /usr/local/bin/pm2
argv : /usr/local/bin/node,/usr/local/bin/pm2,report
argv0 : node
user : georgeashton
uid : 503
gid : 20
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : darwin
type : Darwin
cpus : Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
cpus nb : 12
freemem : 18042880
totalmem : 17179869184
home : /Users/georgeashton
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/Users/georgeashton/.pm2/pm2.log last 20 lines:
PM2 | 2021-07-16T12:52:39: PM2 log: ===============================================================================
PM2 | 2021-07-16T12:52:39: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2 | 2021-07-16T12:52:39: PM2 log: Time : Fri Jul 16 2021 12:52:39 GMT+0100 (British Summer Time)
PM2 | 2021-07-16T12:52:39: PM2 log: PM2 version : 5.1.0
PM2 | 2021-07-16T12:52:39: PM2 log: Node.js version : 14.15.5
PM2 | 2021-07-16T12:52:39: PM2 log: Current arch : x64
PM2 | 2021-07-16T12:52:39: PM2 log: PM2 home : /Users/georgeashton/.pm2
PM2 | 2021-07-16T12:52:39: PM2 log: PM2 PID file : /Users/georgeashton/.pm2/pm2.pid
PM2 | 2021-07-16T12:52:39: PM2 log: RPC socket file : /Users/georgeashton/.pm2/rpc.sock
PM2 | 2021-07-16T12:52:39: PM2 log: BUS socket file : /Users/georgeashton/.pm2/pub.sock
PM2 | 2021-07-16T12:52:39: PM2 log: Application log path : /Users/georgeashton/.pm2/logs
PM2 | 2021-07-16T12:52:39: PM2 log: Worker Interval : 30000
PM2 | 2021-07-16T12:52:39: PM2 log: Process dump file : /Users/georgeashton/.pm2/dump.pm2
PM2 | 2021-07-16T12:52:39: PM2 log: Concurrent actions : 2
PM2 | 2021-07-16T12:52:39: PM2 log: SIGTERM timeout : 1600
PM2 | 2021-07-16T12:52:39: PM2 log: ===============================================================================
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided JavaScript API flow with pm2.stop(task), then compare it with the working CLI command, pm2 stop . Trace the implementation reached by pm2.stop and verify that stopping one task does not trigger repeated failed-to-kill messages or terminate unrelated processes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100