Skip to content

Node.js based forum software built for the modern web

fixed #1395

Julian Lam5b38c3b9eebc
diff --git a/app.js b/app.js
index 5d336a44fd..c7f3d637a6 100644
--- a/app.js
+++ b/app.js
@@ -122,7 +122,8 @@ function start() {
webserver = require('./src/webserver'),
sockets = require('./src/socket.io'),
plugins = require('./src/plugins'),
- upgrade = require('./src/upgrade');
+ upgrade = require('./src/upgrade')
+ meta = require('./src/meta');
templates.setGlobal('relative_path', nconf.get('relative_path'));
@@ -142,6 +143,10 @@ function start() {
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
process.on('SIGHUP', restart);
+ process.on('uncaughtException', function() {
+ meta.js.killMinifier();
+ shutdown();
+ })
} else {
winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:');
winston.warn(' node app --upgrade');
@@ -281,7 +286,7 @@ function shutdown(code) {
winston.info('[app] Database connection closed.');
winston.info('[app] Shutdown complete.');
- process.exit();
+ process.exit(1);
}
function restart() {
diff --git a/loader.js b/loader.js
index 204892b741..13400d67d8 100644
--- a/loader.js
+++ b/loader.js
@@ -8,8 +8,7 @@ var nconf = require('nconf'),
nbb_start = function() {
if (timesStarted > 3) {
console.log('\n[loader] Experienced three start attempts in 10 seconds, most likely am error on startup. Halting.');
- process.exit();
- return;
+ return nbb_stop();
}
timesStarted++;
@@ -54,7 +53,7 @@ var nconf = require('nconf'),
}
},
nbb_restart = function() {
- nbb.on('exit', function() {
+ nbb.removeAllListeners('exit').on('exit', function() {
nbb_start();
});
nbb.kill();
diff --git a/src/meta.js b/src/meta.js
index d7766e418d..c7d14cda19 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -296,7 +296,7 @@ var fs = require('fs'),
},
minify: function(minify) {
// Prepare js for minification/concatenation
- var minifier = fork('minifier.js');
+ var minifier = this.minifierProc = fork('minifier.js');
minifier.on('message', function(payload) {
if (payload.action !== 'error') {
@@ -317,6 +317,11 @@ var fs = require('fs'),
scripts: Meta.js.scripts
});
});
+ },
+ killMinifier: function(callback) {
+ if (this.minifierProc) {
+ this.minifierProc.kill('SIGTERM');
+ }
}
};