0x/lib/preload/no-cluster.js
Renée Kooi fb59f94773
Throw error if a cluster subprocess is forked
0x doesn't support it.

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
```
2018-08-24 11:32:10 +02:00

6 lines
119 B
JavaScript

const cluster = require('cluster')
cluster.on('fork', () => {
throw new Error('0x does not support clustering.')
})