fix(perf): Disable wtfnode dump by default

Consumes a lot of CPU so it's better to enable it on purpose
This commit is contained in:
Chocobozzz 2021-04-13 10:10:56 +02:00 committed by webzwo0i
parent 951d369e3f
commit a001a13411
4 changed files with 36 additions and 8 deletions

View file

@ -463,6 +463,11 @@
*/ */
"loadTest": "${LOAD_TEST:false}", "loadTest": "${LOAD_TEST:false}",
/**
* Disable dump of objects preventing a clean exit
*/
"dumpOnUncleanExit": false,
/* /*
* Disable indentation on new line when previous line ends with some special * Disable indentation on new line when previous line ends with some special
* chars (':', '[', '(', '{') * chars (':', '[', '(', '{')

View file

@ -468,6 +468,11 @@
*/ */
"loadTest": false, "loadTest": false,
/**
* Disable dump of objects preventing a clean exit
*/
"dumpOnUncleanExit": false,
/* /*
* Disable indentation on new line when previous line ends with some special * Disable indentation on new line when previous line ends with some special
* chars (':', '[', '(', '{') * chars (':', '[', '(', '{')

View file

@ -27,9 +27,14 @@
const log4js = require('log4js'); const log4js = require('log4js');
log4js.replaceConsole(); log4js.replaceConsole();
// wtfnode should be loaded after log4js.replaceConsole() so that it uses log4js for logging, and it const settings = require('./utils/Settings');
// should be above everything else so that it can hook in before resources are used.
const wtfnode = require('wtfnode'); let wtfnode;
if (settings.dumpOnUncleanExit) {
// wtfnode should be loaded after log4js.replaceConsole() so that it uses log4js for logging, and
// it should be above everything else so that it can hook in before resources are used.
wtfnode = require('wtfnode');
}
/* /*
* early check for version compatibility before calling * early check for version compatibility before calling
@ -45,7 +50,6 @@ const express = require('./hooks/express');
const hooks = require('../static/js/pluginfw/hooks'); const hooks = require('../static/js/pluginfw/hooks');
const pluginDefs = require('../static/js/pluginfw/plugin_defs'); const pluginDefs = require('../static/js/pluginfw/plugin_defs');
const plugins = require('../static/js/pluginfw/plugins'); const plugins = require('../static/js/pluginfw/plugins');
const settings = require('./utils/Settings');
const stats = require('./stats'); const stats = require('./stats');
const logger = log4js.getLogger('server'); const logger = log4js.getLogger('server');
@ -248,16 +252,25 @@ exports.exit = async (err = null) => {
exitGate = new Gate(); exitGate = new Gate();
state = State.EXITING; state = State.EXITING;
exitGate.resolve(); exitGate.resolve();
// Node.js should exit on its own without further action. Add a timeout to force Node.js to exit // Node.js should exit on its own without further action. Add a timeout to force Node.js to exit
// just in case something failed to get cleaned up during the shutdown hook. unref() is called on // just in case something failed to get cleaned up during the shutdown hook. unref() is called
// the timeout so that the timeout itself does not prevent Node.js from exiting. // on the timeout so that the timeout itself does not prevent Node.js from exiting.
setTimeout(() => { setTimeout(() => {
logger.error('Something that should have been cleaned up during the shutdown hook (such as ' + logger.error('Something that should have been cleaned up during the shutdown hook (such as ' +
'a timer, worker thread, or open connection) is preventing Node.js from exiting'); 'a timer, worker thread, or open connection) is preventing Node.js from exiting');
wtfnode.dump();
if (settings.dumpOnUncleanExit) {
wtfnode.dump();
} else {
logger.error('Enable `dumpOnUncleanExit` setting to get a dump of objects preventing a ' +
'clean exit');
}
logger.error('Forcing an unclean exit...'); logger.error('Forcing an unclean exit...');
process.exit(1); process.exit(1);
}, 5000).unref(); }, 5000).unref();
logger.info('Waiting for Node.js to exit...'); logger.info('Waiting for Node.js to exit...');
state = State.WAITING_FOR_EXIT; state = State.WAITING_FOR_EXIT;
/* eslint-enable no-process-exit */ /* eslint-enable no-process-exit */

View file

@ -250,6 +250,11 @@ exports.automaticReconnectionTimeout = 0;
*/ */
exports.loadTest = false; exports.loadTest = false;
/**
* Disable dump of objects preventing a clean exit
*/
exports.dumpOnUncleanExit = false;
/** /**
* Enable indentation on new lines * Enable indentation on new lines
*/ */