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 crash on stopping app or reboot while watching (Cannot read property 'on' of undefined /pm2/lib/TreeKill.js)) #2646

Closed
evaisse opened this issue Jan 19, 2017 · 2 comments

Comments

@evaisse
Copy link

evaisse commented Jan 19, 2017

Expected behaviour

App should be reloading every time I trigger pm2 stop, pm2 start -f or modify the files using --watch option. But instead each time pm2 try to manage the process, pm2 die with PM2 global error caught.

It get stuck when calling for a stoping command like pm2 stop app. Calling the command a second time seems to get the job done.

<evaisse:~/> pm2 start server.js
[PM2] Starting /server.js in fork_mode (1 instance)
[PM2] Done.
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────────┐
│ App name │ id │ mode │ pid   │ status │ restart │ uptime │ cpu │ mem       │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────────┤
│ server   │ 0  │ fork │ 72050 │ online │ 0       │ 0s     │ 0%  │ 15.5 MB   │ disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

<evaisse:~/> pm2 stop server
[PM2] Applying action stopProcessId on app [server](ids: 0)
^C

<evaisse:~/> pm2 stop server
[PM2] Spawning PM2 daemon with pm2_home=/Users/evaisse/.pm2
[PM2] PM2 Successfully daemonized
[PM2][ERROR] Process server not found
┌──────────┬────┬──────┬─────┬────────┬─────────┬────────┬─────┬─────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ watching │
└──────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────┴─────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

Actual behaviour

PM2 crash every time with no logs

Steps to reproduce

pm2 start app.js
pm2 stop app.js

or

pm2 start app.js --watch

Software versions used

OS         : Mac OS x 10.12.02
node.js    : 6.9.
PM2        : 2.2.3

PM2 Log output

Use the command: tail --lines 50 ~/.pm2/pm2.log

<evaisse:~/Sites/web-es-streaming-01> tail -n 50 ~/.pm2/pm2.log
2017-01-19 17:17:40: Time                 : Thu Jan 19 2017 17:17:40 GMT+0100 (CET)
2017-01-19 17:17:40: PM2 version          : 2.2.3
2017-01-19 17:17:40: Node.js version      : 6.9.4
2017-01-19 17:17:40: Current arch         : x64
2017-01-19 17:17:40: PM2 home             : /Users/evaisse/.pm2
2017-01-19 17:17:40: PM2 PID file         : /Users/evaisse/.pm2/pm2.pid
2017-01-19 17:17:40: RPC socket file      : /Users/evaisse/.pm2/rpc.sock
2017-01-19 17:17:40: BUS socket file      : /Users/evaisse/.pm2/pub.sock
2017-01-19 17:17:40: Application log path : /Users/evaisse/.pm2/logs
2017-01-19 17:17:40: Process dump file    : /Users/evaisse/.pm2/dump.pm2
2017-01-19 17:17:40: Concurrent actions   : 2
2017-01-19 17:17:40: SIGTERM timeout      : 1600
2017-01-19 17:17:40: ===============================================================================
2017-01-19 17:17:53: [Watch] Start watching 0
2017-01-19 17:17:53: Starting execution sequence in -fork mode- for app name:server id:0
2017-01-19 17:17:53: App name:server id:0 online
2017-01-19 17:17:55: [Watch] Stop watching 0
2017-01-19 17:17:55: Stopping app:server id:0
2017-01-19 17:17:57: ===============================================================================
2017-01-19 17:17:57: --- PM2 global error caught ---------------------------------------------------
2017-01-19 17:17:57: Time                 : Thu Jan 19 2017 17:17:57 GMT+0100 (CET)
2017-01-19 17:17:57: Cannot read property 'on' of undefined
2017-01-19 17:17:57: TypeError: Cannot read property 'on' of undefined
    at buildProcessTree (/usr/local/lib/node_modules/pm2/lib/TreeKill.js:86:14)
    at /usr/local/lib/node_modules/pm2/lib/TreeKill.js:107:11
    at Array.forEach (native)
    at ChildProcess.onClose (/usr/local/lib/node_modules/pm2/lib/TreeKill.js:102:31)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
2017-01-19 17:17:57: ===============================================================================
2017-01-19 17:17:57: [PM2][%s] Resurrecting PM2
/usr/local/lib/node_modules/pm2/lib/TreeKill.js:86
    ps.stdout.on('data', function (data) {
             ^

TypeError: Cannot read property 'on' of undefined
    at buildProcessTree (/usr/local/lib/node_modules/pm2/lib/TreeKill.js:86:14)
    at /usr/local/lib/node_modules/pm2/lib/TreeKill.js:107:11
    at Array.forEach (native)
    at ChildProcess.onClose (/usr/local/lib/node_modules/pm2/lib/TreeKill.js:102:31)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)

@evaisse evaisse changed the title Unable to reboot app on watching PM2 crash on stopping app or reboot while watching (Cannot read property 'on' of undefined /pm2/lib/TreeKill.js)) Jan 19, 2017
@vmarchaud
Copy link
Contributor

Landed in pm2 2.3.0

@evaisse
Copy link
Author

evaisse commented Jan 23, 2017

Great ! Thanks !

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

No branches or pull requests

3 participants