forked from svrjs/svrjs
Change the way of adding process message listeners, and add process message listener to server error handler.
This commit is contained in:
parent
45815957d5
commit
58cb60fb8f
3 changed files with 30 additions and 15 deletions
|
@ -18,23 +18,21 @@ function serverErrorHandler(err, isRedirect, server, start) {
|
||||||
(isRedirect ? attmtsRedir : attmts) + " attempts left.",
|
(isRedirect ? attmtsRedir : attmts) + " attempts left.",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// TODO: worker message listener
|
try {
|
||||||
/*try {
|
|
||||||
process.send("\x12ERRLIST" + (isRedirect ? attmtsRedir : attmts) + err.code);
|
process.send("\x12ERRLIST" + (isRedirect ? attmtsRedir : attmts) + err.code);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Probably main process exited
|
// Probably main process exited
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
if ((isRedirect ? attmtsRedir : attmts) > 0) {
|
if ((isRedirect ? attmtsRedir : attmts) > 0) {
|
||||||
server.close();
|
server.close();
|
||||||
setTimeout(start, 900);
|
setTimeout(start, 900);
|
||||||
} else {
|
} else {
|
||||||
// TODO: worker message listener
|
try {
|
||||||
/*try {
|
|
||||||
if (cluster.isPrimary !== undefined) process.send("\x12ERRCRASH" + err.code);
|
if (cluster.isPrimary !== undefined) process.send("\x12ERRCRASH" + err.code);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Probably main process exited
|
// Probably main process exited
|
||||||
}*/
|
}
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var errno = os.constants.errno[err.code];
|
var errno = os.constants.errno[err.code];
|
||||||
process.exit(errno !== undefined ? errno : 1);
|
process.exit(errno !== undefined ? errno : 1);
|
||||||
|
@ -47,6 +45,21 @@ serverErrorHandler.resetAttempts = (isRedirect) => {
|
||||||
else attmts = 5;
|
else attmts = 5;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
process.messageEventListeners.push((worker, serverconsole) => {
|
||||||
|
return (message) => {
|
||||||
|
if (message.indexOf("\x12ERRLIST") == 0) {
|
||||||
|
const tries = parseInt(msg.substring(8, 9));
|
||||||
|
const errCode = msg.substring(9);
|
||||||
|
serverconsole.locerrmessage(serverErrorDescs[errCode] ? serverErrorDescs[errCode] : serverErrorDescs["UNKNOWN"]);
|
||||||
|
serverconsole.locmessage(tries + " attempts left.");
|
||||||
|
}
|
||||||
|
if (message.length >= 9 && msg.indexOf("\x12ERRCRASH") == 0) {
|
||||||
|
const errno = errors[msg.substring(9)];
|
||||||
|
process.exit(errno !== undefined ? errno : 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = (serverconsoleO) => {
|
module.exports = (serverconsoleO) => {
|
||||||
serverconsole = serverconsoleO;
|
serverconsole = serverconsoleO;
|
||||||
return serverErrorHandler;
|
return serverErrorHandler;
|
||||||
|
|
|
@ -92,6 +92,8 @@ process.err5xxcounter = 0;
|
||||||
process.reqcounter = 0;
|
process.reqcounter = 0;
|
||||||
process.malformedcounter = 0;
|
process.malformedcounter = 0;
|
||||||
|
|
||||||
|
process.messageEventListeners = [];
|
||||||
|
|
||||||
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
|
if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into process.versions
|
||||||
|
|
||||||
let exiting = false;
|
let exiting = false;
|
||||||
|
|
|
@ -422,8 +422,8 @@ module.exports = (req, res, logFacilities, config, next) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// IPC listener for brute force protection
|
// IPC listener for brute force protection
|
||||||
module.exports.mainMessageListenerWrapper = (worker) => {
|
process.messageEventListeners.push((worker, serverconsole) => {
|
||||||
return function bruteForceListener(message) {
|
return (message) => {
|
||||||
let ip = "";
|
let ip = "";
|
||||||
if (message.substring(0, 6) == "\x12AUTHQ") {
|
if (message.substring(0, 6) == "\x12AUTHQ") {
|
||||||
ip = message.substring(6);
|
ip = message.substring(6);
|
||||||
|
@ -458,7 +458,7 @@ module.exports.mainMessageListenerWrapper = (worker) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
|
|
||||||
module.exports.commands = {
|
module.exports.commands = {
|
||||||
stop: (args, log, passCommand) => {
|
stop: (args, log, passCommand) => {
|
||||||
|
|
Reference in a new issue