Fixes a bug where exceptions caused by the inbound socket on HTTPServer are not caught

This commit is contained in:
Zachary Boyd 2018-09-10 13:25:39 -04:00
parent c43e6cf14f
commit 94a6511fd5
2 changed files with 13 additions and 10 deletions

View file

@ -176,16 +176,14 @@ class HTTPServer extends Server {
inbound_socket && inbound_socket.end();
outbound_socket && outbound_socket.end();
inbound_socket = outbound_socket = buffer = void(0);
inbound_socket = outbound_socket = void(0);
if (error)
if (error instanceof Error)
this.logger.error(`[http-connect]: an error occured: ${error.message}`)
};
var buffer = [head];
let onInboundData = function (data) {
buffer.push(data);
};
inbound_socket.on('error', onClose);
inbound_socket.on('close', onClose);
socks.connect({
host: hostname,
@ -196,8 +194,8 @@ class HTTPServer extends Server {
auths: [ socks.auth.None() ]
}, ($outbound_socket) => {
outbound_socket = $outbound_socket;
outbound_socket && outbound_socket.on('close', onClose);
outbound_socket && outbound_socket.on('error', onClose);
outbound_socket.on('close', onClose);
outbound_socket.on('error', onClose);
inbound_socket.write(`HTTP/1.1 200 Connection Established\r\n'+'Proxy-agent: ${TOR_ROUTER_PROXY_AGENT}\r\n` +'\r\n');
outbound_socket.write(head);

View file

@ -95,9 +95,10 @@ async function main(nconf, logger) {
thereWasAnExitError = true;
}
if (handleError && error) {
console.log(error)
if (error instanceof Error) {
logger.error(`[global]: error shutting down: ${error.message}`);
} else {
error = 0;
}
process.exit(Number(Boolean(error || thereWasAnExitError)));
@ -191,6 +192,10 @@ nconf
let nconf_config = nconf.get('config');
if (nconf_config) {
if (!require('fs').existsSync(nconf_config)) {
console.error(`[global]: config file "${nconf_config}" does not exist. exiting.`);
process.exit(1);
}
nconf.file(nconf_config);
} else {
nconf.use('memory');