indexzero / ps-tree

MIT License
149 stars 29 forks source link

Crash when running childrenOfPid when app is exiting #21

Open majg0 opened 7 years ago

majg0 commented 7 years ago

Just had the following crash, and it seems the problem originates here.

  ...
42.  var processLister;
43.  if (process.platform === 'win32') {
  ...
46.  } else {
47.    processLister = spawn('ps', ['-A', '-o', 'ppid,pid,stat,comm']);
  ...
50.  es.connect(
  ...
52.    processLister.stdout, // this is undefined
  ...
TypeError: Cannot read property 'on' of undefined
    at duplex (/Users/mg/w/git/nxt-render/node_modules/duplexer/index.js:31:11)
    at Object.module.exports (/Users/mg/w/git/nxt-render/node_modules/stream-combiner/index.js:8:17)
    at childrenOfPid (/Users/mg/w/git/nxt-render/node_modules/ps-tree/index.js:50:6)
    at kill (/Users/mg/w/git/nxt-render/node_modules/nodemon/lib/monitor/run.js:281:7)
    at Function.run.kill (/Users/mg/w/git/nxt-render/node_modules/nodemon/lib/monitor/run.js:214:9)
    at Bus.<anonymous> (/Users/mg/w/git/nxt-render/node_modules/nodemon/lib/monitor/run.js:346:7)
    at emitOne (events.js:120:20)
    at Bus.emit (events.js:210:7)
    at restartBus (/Users/mg/w/git/nxt-render/node_modules/nodemon/lib/monitor/watch.js:162:7)
    at FSWatcher.filterAndRestart (/Users/mg/w/git/nxt-render/node_modules/nodemon/lib/monitor/watch.js:145:16)
juliangruber commented 2 years ago

I just saw the same, node docs explains:

The subprocess.stdout property can be null if the child process could not be successfully spawned.

Since this fails synchronously, one should be able to catch it. I'm going to open a PR for this

juliangruber commented 2 years ago

Fix in https://github.com/indexzero/ps-tree/pull/52