Skip to content

Node.js based forum software built for the modern web

added startTimer so that repeated errors on startup don't cause the loader to go into an infinite loop

Julian Lam74ff57941257
diff --git a/loader.js b/loader.js
index e0bfac6258..20f9d49f88 100644
--- a/loader.js
+++ b/loader.js
@@ -6,6 +6,18 @@ var nconf = require('nconf'),
start = function() {
var fork = require('child_process').fork,
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;
+ }
+
+ timesStarted++;
+ if (startTimer) {
+ clearTimeout(startTimer);
+ }
+ startTimer = setTimeout(resetTimer, 1000*10);
+
nbb = fork('./app', process.argv.slice(2), {
env: {
'NODE_ENV': process.env.NODE_ENV
@@ -29,6 +41,10 @@ var nconf = require('nconf'),
});
},
nbb_stop = function() {
+ if (startTimer) {
+ clearTimeout(startTimer);
+ }
+
nbb.kill();
if (fs.existsSync(pidFilePath)) {
var pid = parseInt(fs.readFileSync(pidFilePath, { encoding: 'utf-8' }), 10);
@@ -42,7 +58,13 @@ var nconf = require('nconf'),
nbb_start();
});
nbb.kill();
- };
+ },
+ resetTimer = function() {
+ clearTimeout(startTimer);
+ timesStarted = 0;
+ },
+ timesStarted = 0,
+ startTimer;
process.on('SIGINT', nbb_stop);
process.on('SIGTERM', nbb_stop);