davidmarkclements / 0x

šŸ”„ single-command flamegraph profiling šŸ”„
MIT License
3.23k stars 106 forks source link

Throw error if a cluster subprocess is forked #155

Closed goto-bus-stop closed 6 years ago

goto-bus-stop commented 6 years ago

0x doesn't support multi processes.

I used the 'fork' event because it's easier than intercepting require and this way it allows requiring but not using cluster. If the subprocess does try { cluster.fork() } this won't crash, but that's probably fine? Same if the subprocess has an 'uncaughtException' handler.

Ex:

āžœ  ./cmd.js cluster.js
šŸ”„  Profiling/home/goto-bus-stop/Code/nearform/0x/lib/preload/no-cluster.js:4
  throw new Error('0x does not support clustering.')
  ^
Error: 0x does not support clustering.
    at EventEmitter.cluster.on (/home/goto-bus-stop/Code/nearform/0x/lib/preload/no-cluster.js:4:9)
    at EventEmitter.emit (events.js:182:13)
    at emitForkNT (internal/cluster/master.js:226:11)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
šŸš«  Target subprocess error, code: 1
// cluster.js
const { isMaster, fork } = require('cluster')
if (isMaster) {
  fork()
} else {
  console.log('hi')
}