Fix all video adds getting stuck when one fails
Whenever a urlRetrieve() fails due to an unexpected error (ENOTFOUND, ETIMEDOUT, Socket hang up, etc.), the domain handler and the global exception handler would detect this and not crash the server, however the dirty internal state would somehow prevent future HTTP requests from completing successfully. Removed domain usage since that feature is marked "unstable" and is rumored to be marked for deprecation in future versions of node. Using the "error" event of the request object itself, which means errors are local in scope and won't pollute global state. This should have been the solution originally, but when urlRetrieve() was written, I was not as familiar with node.
This commit is contained in:
parent
db7d1a22c8
commit
3689aafe3b
|
@ -10,7 +10,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||||
*/
|
*/
|
||||||
var http = require("http");
|
var http = require("http");
|
||||||
var https = require("https");
|
var https = require("https");
|
||||||
var domain = require("domain");
|
|
||||||
var Logger = require("./logger.js");
|
var Logger = require("./logger.js");
|
||||||
var Media = require("./media");
|
var Media = require("./media");
|
||||||
var CustomEmbedFilter = require("./customembed").filter;
|
var CustomEmbedFilter = require("./customembed").filter;
|
||||||
|
@ -44,19 +43,6 @@ const CONTENT_TYPES = {
|
||||||
};
|
};
|
||||||
|
|
||||||
var urlRetrieve = function (transport, options, callback) {
|
var urlRetrieve = function (transport, options, callback) {
|
||||||
// Catch any errors that crop up along the way of the request
|
|
||||||
// in order to prevent them from reaching the global handler.
|
|
||||||
// This should cut down on needing to restart the server
|
|
||||||
var d = domain.create();
|
|
||||||
d.on("error", function (err) {
|
|
||||||
Logger.errlog.log(err.stack);
|
|
||||||
Logger.errlog.log("urlRetrieve failed: " + err);
|
|
||||||
Logger.errlog.log("Request was: " + options.host + options.path);
|
|
||||||
setImmediate(function () {
|
|
||||||
callback(503, "");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
d.run(function () {
|
|
||||||
var req = transport.request(options, function (res) {
|
var req = transport.request(options, function (res) {
|
||||||
var buffer = "";
|
var buffer = "";
|
||||||
res.setEncoding("utf-8");
|
res.setEncoding("utf-8");
|
||||||
|
@ -68,8 +54,13 @@ var urlRetrieve = function (transport, options, callback) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.end();
|
req.on("error", function (err) {
|
||||||
|
Logger.errlog.log("HTTP request " + options.host + options.path + " failed: " +
|
||||||
|
err);
|
||||||
|
callback(503, "");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
req.end();
|
||||||
};
|
};
|
||||||
|
|
||||||
var Getters = {
|
var Getters = {
|
||||||
|
|
Loading…
Reference in a new issue