mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 08:20:36 +01:00
testing socket availability before attempting to bind
This commit is contained in:
@@ -220,11 +220,15 @@ function killWorkers() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader.notifyWorkers = function (msg, worker_pid) {
|
Loader.notifyWorkers = function(msg, worker_pid) {
|
||||||
worker_pid = parseInt(worker_pid, 10);
|
worker_pid = parseInt(worker_pid, 10);
|
||||||
workers.forEach(function(worker) {
|
workers.forEach(function(worker) {
|
||||||
if (parseInt(worker.pid, 10) !== worker_pid) {
|
if (parseInt(worker.pid, 10) !== worker_pid) {
|
||||||
worker.send(msg);
|
try {
|
||||||
|
worker.send(msg);
|
||||||
|
} catch (e) {
|
||||||
|
console.log('[cluster/notifyWorkers] Failed to reach pid ' + worker_pid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ var path = require('path'),
|
|||||||
routes = require('./routes'),
|
routes = require('./routes'),
|
||||||
emitter = require('./emitter'),
|
emitter = require('./emitter'),
|
||||||
|
|
||||||
helpers = require('./../public/src/helpers')();
|
helpers = require('./../public/src/helpers')(),
|
||||||
|
net;
|
||||||
|
|
||||||
if(nconf.get('ssl')) {
|
if(nconf.get('ssl')) {
|
||||||
server = require('https').createServer({
|
server = require('https').createServer({
|
||||||
@@ -104,14 +105,9 @@ if(nconf.get('ssl')) {
|
|||||||
bind_address = ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port,
|
bind_address = ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port,
|
||||||
oldUmask;
|
oldUmask;
|
||||||
|
|
||||||
// Alter umask if necessary
|
|
||||||
if (isSocket) {
|
|
||||||
oldUmask = process.umask('0000');
|
|
||||||
}
|
|
||||||
|
|
||||||
args.push(function(err) {
|
args.push(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.info('NodeBB was unable to listen on: ' + bind_address);
|
winston.info('[startup] NodeBB was unable to listen on: ' + bind_address);
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +119,47 @@ if(nconf.get('ssl')) {
|
|||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen.apply(server, args);
|
// Alter umask if necessary
|
||||||
|
if (isSocket) {
|
||||||
|
oldUmask = process.umask('0000');
|
||||||
|
net = require('net');
|
||||||
|
module.exports.testSocket(port, function(err) {
|
||||||
|
if (!err) {
|
||||||
|
server.listen.apply(server, args);
|
||||||
|
} else {
|
||||||
|
winston.error('[startup] NodeBB was unable to secure domain socket access (' + port + ')');
|
||||||
|
winston.error('[startup] ' + err.message);
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
server.listen.apply(server, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.testSocket = function(socketPath, callback) {
|
||||||
|
async.series([
|
||||||
|
function(next) {
|
||||||
|
fs.exists(socketPath, function(exists) {
|
||||||
|
if (exists) {
|
||||||
|
next();
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
var testSocket = new net.Socket();
|
||||||
|
testSocket.on('error', function(err) {
|
||||||
|
next(err.code !== 'ECONNREFUSED' ? err : null);
|
||||||
|
});
|
||||||
|
testSocket.connect({ path: socketPath }, function() {
|
||||||
|
// Something's listening here, abort
|
||||||
|
callback(new Error('port-in-use'));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async.apply(fs.unlink, socketPath), // The socket was stale, kick it out of the way
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
}(WebServer));
|
}(WebServer));
|
||||||
|
|||||||
Reference in New Issue
Block a user