mirror of https://github.com/calzoneman/sync.git
Add more safeguards for socket errors
This commit is contained in:
parent
cd22570c40
commit
414cbfdc5d
|
@ -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,18 +985,16 @@ function vimeoWorkaround(id, cb) {
|
|||
}
|
||||
};
|
||||
|
||||
http.get(options, function (res) {
|
||||
res.setEncoding("utf-8");
|
||||
var buffer = "";
|
||||
|
||||
res.on("data", function (data) {
|
||||
buffer += data;
|
||||
urlRetrieve(http, options, function (status, buffer) {
|
||||
if (status !== 200) {
|
||||
setImmediate(function () {
|
||||
cb({});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res.on("end", function () {
|
||||
parse(buffer);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
inner();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue