Skip to content
Snippets Groups Projects
Commit 726b4f36 authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

for __heartbeat__ use an application level global timeout to catch the...

for __heartbeat__ use an application level global timeout to catch the situation where the other end is not reachable and ensure total wait time is <= 5s (in this case, no 'connect' event is ever emitted)
parent 66496c67
No related branches found
No related tags found
No related merge requests found
......@@ -92,11 +92,16 @@ var check = exports.check = function(url, cb) {
var shortname = url.host + ':' + url.port;
var timeoutHandle = setTimeout(function() {
req.abort();
}, checkTimeout);
var req = require(url.scheme).get({
host: url.host,
port: url.port,
path: exports.path
}, function (res) {
clearTimeout(timeoutHandle);
if (res.statusCode === 200) cb(true);
else {
logger.error("non-200 response from " + shortname + ". fatal! (" + res.statusCode + ")");
......@@ -104,14 +109,8 @@ var check = exports.check = function(url, cb) {
}
});
req.on('error', function (e) {
clearTimeout(timeoutHandle);
logger.error("can't communicate with " + shortname + ". fatal: " + e);
cb(false, e);
});
req.on('connect', function (socket) {
socket.setTimeout(checkTimeout);
socket.on('timeout', function() {
req.abort();
cb(false, "timeout");
});
});
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment