process: move initialization of node-report into pre_execution.js
- Splits signal handler setup code into two functions: one sets up `process.on('SIGNAL_NAME')`, another takes care of the signal triggers of node-report. Both should only happen on the main thread. The latter needs to happen after the node-report configurations are read into the process. - Move the initialization of node-report into pre_execution.js because it depends on CLI/environment settings. PR-URL: https://github.com/nodejs/node/pull/26227 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
34470b0524
commit
b0869c64d1
@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
const { internalBinding, NativeModule } = loaderExports;
|
const { internalBinding, NativeModule } = loaderExports;
|
||||||
const { Object, Symbol } = primordials;
|
const { Object, Symbol } = primordials;
|
||||||
const { getOptionValue } = NativeModule.require('internal/options');
|
|
||||||
const config = internalBinding('config');
|
const config = internalBinding('config');
|
||||||
const { deprecate } = NativeModule.require('internal/util');
|
const { deprecate } = NativeModule.require('internal/util');
|
||||||
|
|
||||||
@ -282,17 +281,6 @@ if (process.env.NODE_V8_COVERAGE) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getOptionValue('--experimental-report')) {
|
|
||||||
const {
|
|
||||||
config,
|
|
||||||
report,
|
|
||||||
syncConfig
|
|
||||||
} = NativeModule.require('internal/process/report');
|
|
||||||
process.report = report;
|
|
||||||
// Download the CLI / ENV config into JS land.
|
|
||||||
syncConfig(config, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupProcessObject() {
|
function setupProcessObject() {
|
||||||
const EventEmitter = NativeModule.require('events');
|
const EventEmitter = NativeModule.require('events');
|
||||||
const origProcProto = Object.getPrototypeOf(process);
|
const origProcProto = Object.getPrototypeOf(process);
|
||||||
|
@ -11,6 +11,10 @@ function prepareMainThreadExecution() {
|
|||||||
// Only main thread receives signals.
|
// Only main thread receives signals.
|
||||||
setupSignalHandlers();
|
setupSignalHandlers();
|
||||||
|
|
||||||
|
// Process initial configurations of node-report, if any.
|
||||||
|
initializeReport();
|
||||||
|
initializeReportSignalHandlers(); // Main-thread-only.
|
||||||
|
|
||||||
// If the process is spawned with env NODE_CHANNEL_FD, it's probably
|
// If the process is spawned with env NODE_CHANNEL_FD, it's probably
|
||||||
// spawned by our child_process module, then initialize IPC.
|
// spawned by our child_process module, then initialize IPC.
|
||||||
// This attaches some internal event listeners and creates:
|
// This attaches some internal event listeners and creates:
|
||||||
@ -31,6 +35,20 @@ function prepareMainThreadExecution() {
|
|||||||
loadPreloadModules();
|
loadPreloadModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initializeReport() {
|
||||||
|
if (!getOptionValue('--experimental-report')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const {
|
||||||
|
config,
|
||||||
|
report,
|
||||||
|
syncConfig
|
||||||
|
} = require('internal/process/report');
|
||||||
|
process.report = report;
|
||||||
|
// Download the CLI / ENV config into JS land.
|
||||||
|
syncConfig(config, false);
|
||||||
|
}
|
||||||
|
|
||||||
function setupSignalHandlers() {
|
function setupSignalHandlers() {
|
||||||
const {
|
const {
|
||||||
createSignalHandlers
|
createSignalHandlers
|
||||||
@ -41,15 +59,20 @@ function setupSignalHandlers() {
|
|||||||
} = createSignalHandlers();
|
} = createSignalHandlers();
|
||||||
process.on('newListener', startListeningIfSignal);
|
process.on('newListener', startListeningIfSignal);
|
||||||
process.on('removeListener', stopListeningIfSignal);
|
process.on('removeListener', stopListeningIfSignal);
|
||||||
|
}
|
||||||
|
|
||||||
if (getOptionValue('--experimental-report')) {
|
// This has to be called after both initializeReport() and
|
||||||
const {
|
// setupSignalHandlers() are called
|
||||||
config,
|
function initializeReportSignalHandlers() {
|
||||||
handleSignal
|
if (!getOptionValue('--experimental-report')) {
|
||||||
} = require('internal/process/report');
|
return;
|
||||||
if (config.events.includes('signal')) {
|
}
|
||||||
process.on(config.signal, handleSignal);
|
const {
|
||||||
}
|
config,
|
||||||
|
handleSignal
|
||||||
|
} = require('internal/process/report');
|
||||||
|
if (config.events.includes('signal')) {
|
||||||
|
process.on(config.signal, handleSignal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,5 +227,6 @@ module.exports = {
|
|||||||
initializeDeprecations,
|
initializeDeprecations,
|
||||||
initializeESMLoader,
|
initializeESMLoader,
|
||||||
loadPreloadModules,
|
loadPreloadModules,
|
||||||
setupTraceCategoryState
|
setupTraceCategoryState,
|
||||||
|
initializeReport
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
const {
|
const {
|
||||||
initializeDeprecations,
|
initializeDeprecations,
|
||||||
initializeESMLoader,
|
initializeESMLoader,
|
||||||
|
initializeReport,
|
||||||
loadPreloadModules,
|
loadPreloadModules,
|
||||||
setupTraceCategoryState
|
setupTraceCategoryState
|
||||||
} = require('internal/bootstrap/pre_execution');
|
} = require('internal/bootstrap/pre_execution');
|
||||||
@ -75,6 +76,7 @@ port.on('message', (message) => {
|
|||||||
} = message;
|
} = message;
|
||||||
|
|
||||||
setupTraceCategoryState();
|
setupTraceCategoryState();
|
||||||
|
initializeReport();
|
||||||
if (manifestSrc) {
|
if (manifestSrc) {
|
||||||
require('internal/process/policy').setup(manifestSrc, manifestURL);
|
require('internal/process/policy').setup(manifestSrc, manifestURL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user