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

src: fix preload timing #1694

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,17 @@
delete process.env.NODE_UNIQUE_ID;
}

// Load any preload modules
if (process._preload_modules) {
var Module = NativeModule.require('module');
process._preload_modules.forEach(function(module) {
Module._load(module);
});
}

if (process._eval != null) {
// User passed '-e' or '--eval' arguments to Node.
startup.preloadModules();
evalScript('[eval]');
} else if (process.argv[1]) {
// make process.argv[1] into a full path
var path = NativeModule.require('path');
process.argv[1] = path.resolve(process.argv[1]);

var Module = NativeModule.require('module');

startup.preloadModules();
if (global.v8debug &&
process.execArgv.some(function(arg) {
return arg.match(/^--debug-brk(=[0-9]*)?$/);
Expand Down Expand Up @@ -857,6 +850,16 @@
};
};

// Load preload modules
startup.preloadModules = function() {
if (process._preload_modules) {
var Module = NativeModule.require('module');
process._preload_modules.forEach(function(module) {
Module._load(module);
});
}
};

// Below you find a minimal module system, which is used to load the node
// core modules found in lib/*.js. All core modules are compiled into the
// node binary, so they can be loaded faster.
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,15 @@ child_process.exec(nodeBinary + ' '
if (err) throw err;
assert.ok(/worker terminated with code 43/.test(stdout));
});

// https://github.com/iojs/io.js/issues/1691
var originalCwd = process.cwd();
process.chdir(path.join(__dirname, '../fixtures/'));
child_process.exec(nodeBinary + ' '
+ '--expose_debug_as=v8debug '
+ '--require ' + fixture('cluster-preload.js') + ' '
+ 'cluster-preload-test.js',
function(err, stdout, stderr) {
if (err) throw err;
assert.ok(/worker terminated with code 43/.test(stdout));
});