Add more safeguards for socket errors

This commit is contained in:
Calvin Montgomery 2015-01-06 10:54:14 -05:00
parent cd22570c40
commit 414cbfdc5d
3 changed files with 37 additions and 11 deletions

View File

@ -34,6 +34,12 @@ const CONTENT_TYPES = {
var urlRetrieve = function (transport, options, callback) {
var req = transport.request(options, function (res) {
res.on("error", function (err) {
Logger.errlog.log("HTTP response " + options.host + options.path + " failed: "+
err);
callback(503, "");
});
var buffer = "";
res.setEncoding("utf-8");
res.on("data", function (chunk) {
@ -979,17 +985,15 @@ function vimeoWorkaround(id, cb) {
}
};
http.get(options, function (res) {
res.setEncoding("utf-8");
var buffer = "";
urlRetrieve(http, options, function (status, buffer) {
if (status !== 200) {
setImmediate(function () {
cb({});
});
return;
}
res.on("data", function (data) {
buffer += data;
});
res.on("end", function () {
parse(buffer);
});
parse(buffer);
});
};

View File

@ -217,7 +217,15 @@ module.exports = {
if (id in srv.servers) {
io.attach(srv.servers[id]);
} else {
io.attach(require("http").createServer().listen(bind.port, bind.ip));
var server = require("http").createServer().listen(bind.port, bind.ip);
server.on("clientError", function (err, socket) {
Logger.errlog.log("clientError on " + id + " - " + err);
try {
socket.destroy();
} catch (e) {
}
});
io.attach(server);
}
bound[id] = null;

View File

@ -85,8 +85,22 @@ var Server = function () {
if (bind.https && Config.get("https.enabled")) {
self.servers[id] = https.createServer(opts, self.express)
.listen(bind.port, bind.ip);
self.servers[id].on("clientError", function (err, socket) {
Logger.errlog.log("clientError on " + id + " - " + err);
try {
socket.destroy();
} catch (e) {
}
});
} else if (bind.http) {
self.servers[id] = self.express.listen(bind.port, bind.ip);
self.servers[id].on("clientError", function (err, socket) {
Logger.errlog.log("clientError on " + id + " - " + err);
try {
socket.destroy();
} catch (e) {
}
});
}
});