From 3689aafe3bdd997b503dfa8188b19dae63679e3b Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Fri, 26 Dec 2014 10:39:47 -0500 Subject: [PATCH] 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. --- lib/get-info.js | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/lib/get-info.js b/lib/get-info.js index 6ff95eae..f4d702e9 100644 --- a/lib/get-info.js +++ b/lib/get-info.js @@ -10,7 +10,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ var http = require("http"); var https = require("https"); -var domain = require("domain"); var Logger = require("./logger.js"); var Media = require("./media"); var CustomEmbedFilter = require("./customembed").filter; @@ -44,32 +43,24 @@ const CONTENT_TYPES = { }; 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, ""); + var req = transport.request(options, function (res) { + var buffer = ""; + res.setEncoding("utf-8"); + res.on("data", function (chunk) { + buffer += chunk; + }); + res.on("end", function () { + callback(res.statusCode, buffer); }); }); - d.run(function () { - var req = transport.request(options, function (res) { - var buffer = ""; - res.setEncoding("utf-8"); - res.on("data", function (chunk) { - buffer += chunk; - }); - res.on("end", function () { - callback(res.statusCode, buffer); - }); - }); - req.end(); + req.on("error", function (err) { + Logger.errlog.log("HTTP request " + options.host + options.path + " failed: " + + err); + callback(503, ""); }); + + req.end(); }; var Getters = {