From aeab31825e696ddd34659c2e424ce423467ee48c Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sun, 21 Jan 2018 18:53:16 -0800 Subject: [PATCH] Fix a raw file error caused by facebook CDN violating RFC 2616 --- package.json | 2 +- src/channel/channel.js | 1 + src/ffmpeg.js | 20 +++++++++++++++++--- src/util/call-once.js | 7 +++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/util/call-once.js diff --git a/package.json b/package.json index 33a6ea22..1afee257 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.53.0", + "version": "3.53.1", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/channel/channel.js b/src/channel/channel.js index 8b9b2a75..6e3b7cf3 100644 --- a/src/channel/channel.js +++ b/src/channel/channel.js @@ -46,6 +46,7 @@ class ReferenceCounter { LOGGER.error("ReferenceCounter::unref() called by caller [" + caller + "] but this caller had no active references! " + `(channel: ${this.channelName})`); + return; } } diff --git a/src/ffmpeg.js b/src/ffmpeg.js index 938f0749..41b48383 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -6,6 +6,8 @@ var http = require("http"); var urlparse = require("url"); var path = require("path"); +import { callOnce } from './util/call-once'; + const LOGGER = require('@calzoneman/jsli')('ffmpeg'); const ECODE_MESSAGES = { ENOTFOUND: e => ( @@ -179,7 +181,19 @@ function testUrl(url, cb, params = { redirCount: 0, cookie: '' }) { return; } - LOGGER.error("Error sending preflight request: %s (code=%s) (link: %s)", err.message, err.code, url); + // HPE_INVALID_CONSTANT comes from node's HTTP parser because + // facebook's CDN violates RFC 2616 by sending a body even though + // the request uses the HEAD method. + // Avoid logging this because it's a known issue. + if (!(err.code === 'HPE_INVALID_CONSTANT' && /fbcdn/.test(url))) { + LOGGER.error( + "Error sending preflight request: %s (code=%s) (link: %s)", + err.message, + err.code, + url + ); + } + cb("An unexpected error occurred while trying to process the link. " + "Try again, and contact support for further troubleshooting if the " + "problem continues." + (!!err.code ? (" Error code: " + err.code) : "")); @@ -387,7 +401,7 @@ exports.query = function (filename, cb) { "Ensure that the link begins with 'https://'."); } - testUrl(filename, function (err) { + testUrl(filename, callOnce(function (err) { if (err) { return cb(err); } @@ -458,5 +472,5 @@ exports.query = function (filename, cb) { "https://git.io/vrE75 for details."); } }); - }); + })); }; diff --git a/src/util/call-once.js b/src/util/call-once.js new file mode 100644 index 00000000..2753a46e --- /dev/null +++ b/src/util/call-once.js @@ -0,0 +1,7 @@ +export function callOnce(fn) { + let called = false; + + return (...args) => { + called || fn(...args), called = true; + } +}