From fbee6d2ab7fcea70d6dd052dbfec8808f04714bf Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sun, 10 Dec 2017 16:39:06 -0800 Subject: [PATCH] Fix a few common causes of error logs (incl. better ffprobe error messages) --- package.json | 2 +- src/channel/channel.js | 2 +- src/ffmpeg.js | 43 +++++++++++++++++++++++++++++++++--------- src/io/ioserver.js | 20 +++++++++++++++++++- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index d95547ad..ddca3414 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.51.7", + "version": "3.51.8", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/channel/channel.js b/src/channel/channel.js index b727fac8..63a2b8a4 100644 --- a/src/channel/channel.js +++ b/src/channel/channel.js @@ -64,7 +64,7 @@ class ReferenceCounter { for (var caller in this.references) { this.refCount += this.references[caller]; } - } else if (this.channel.users.length > 0) { + } else if (this.channel.users && this.channel.users.length > 0) { LOGGER.error("ReferenceCounter::refCount reached 0 but still had " + this.channel.users.length + " active users" + ` (channel: ${this.channelName})`); diff --git a/src/ffmpeg.js b/src/ffmpeg.js index 69e9603c..4edf0235 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -7,6 +7,37 @@ var urlparse = require("url"); var path = require("path"); const LOGGER = require('@calzoneman/jsli')('ffmpeg'); +const ECODE_MESSAGES = { + ENOTFOUND: e => ( + `Unknown host "${e.hostname}". ` + + 'Please check that the link is correct.' + ), + EPROTO: e => 'The remote server does not support HTTPS.', + ECONNREFUSED: e => ( + 'The remote server refused the connection. ' + + 'Please check that the link is correct and the server is running.' + ), + ETIMEDOUT: e => ( + 'The connection to the remote server timed out. ' + + 'Please check that the link is correct.' + ), + ENETUNREACH: e => ( + "The remote server's network is unreachable from this server. " + + "Please contact an administrator for assistance." + ), + + DEPTH_ZERO_SELF_SIGNED_CERT: e => ( + 'The remote server provided an invalid ' + + '(self-signed) SSL certificate. Raw file support requires a ' + + 'trusted certificate. See https://letsencrypt.org/ to get ' + + 'a free, trusted certificate.' + ), + UNABLE_TO_VERIFY_LEAF_SIGNATURE: e => ( + "The remote server's SSL certificate chain could not be validated. " + + "Please contact the administrator of the server to correct their " + + "SSL certificate configuration." + ) +}; var USE_JSON = true; var TIMEOUT = 30000; @@ -138,18 +169,12 @@ function testUrl(url, cb, params = { redirCount: 0, cookie: '' }) { cb("The remote server provided an invalid SSL certificate. Details: " + err.reason); return; - } else if (err.code === 'ENOTFOUND') { - cb(`Unknown host "${err.hostname}". Please check that the link is correct.`); - return; - } else if (err.code === 'ECONNREFUSED') { - cb("The remote server refused the connection. Please check that the link is correct."); - return; - } else if (err.code === 'ETIMEDOUT') { - cb("The connection to the remote server timed out. Please check that the link is correct."); + } else if (ECODE_MESSAGES.hasOwnProperty(err.code)) { + cb(`${ECODE_MESSAGES[err.code](err)} (error code: ${err.code})`); return; } - LOGGER.error("Error sending preflight request: %s (link: %s)", err.message, 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) : "")); diff --git a/src/io/ioserver.js b/src/io/ioserver.js index 6a7a66c3..927430ea 100644 --- a/src/io/ioserver.js +++ b/src/io/ioserver.js @@ -50,10 +50,28 @@ class IOServer { // If the resulting address is a known Tor exit, flag it as such ipProxyMiddleware(socket, next) { if (!socket.context) socket.context = {}; - socket.context.ipAddress = proxyaddr(socket.client.request, this.proxyTrustFn); + + try { + socket.context.ipAddress = proxyaddr( + socket.client.request, + this.proxyTrustFn + ); + + if (!socket.context.ipAddress) { + throw new Error( + `Assertion failed: unexpected IP ${socket.context.ipAddress}` + ); + } + } catch (error) { + LOGGER.warn('Rejecting socket - proxyaddr failed: %s', error); + next(new Error('Could not determine IP address')); + return; + } + if (isTorExit(socket.context.ipAddress)) { socket.context.torConnection = true; } + next(); }