Skip to content

Instantly share code, notes, and snippets.

@JLHwung
Created January 15, 2021 15:52
Show Gist options
  • Save JLHwung/631dfbf4a4c68d85ae7a9b7ab5fa9754 to your computer and use it in GitHub Desktop.
Save JLHwung/631dfbf4a4c68d85ae7a9b7ab5fa9754 to your computer and use it in GitHub Desktop.
Forked cluster does not fixup process.execArgv when executed by module.runMain()
node --expose_gc ./wrapper.js ./payload.js

Expected:

[Function: gc] true
[Function: gc]

Actual (v15.5.1)

[Function: gc] true
undefined
const cluster = require("cluster");
if (cluster.isMaster) {
console.log(globalThis.gc, cluster.isMaster);
cluster.fork();
} else {
console.log(globalThis.gc);
process.kill(process.pid);
}
#!/usr/bin/env node
const { isAbsolute, join } = require("path");
const args = process.argv[process.argv.length - 1];
const filename = args[0];
if (!isAbsolute(filename)) {
args[0] = join(process.cwd(), filename);
}
process.argv = ["node"].concat(args);
process.execArgv.unshift(__filename);
require("module").runMain();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment