From 5bbf57a57a6be8aa62dff3bbbc2523865b49ee31 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Thu, 18 May 2017 14:14:44 -0600 Subject: [PATCH] tweaked proxy behavior on error/close --- lib/proxy-conn.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/proxy-conn.js b/lib/proxy-conn.js index 476546c..b9a704c 100644 --- a/lib/proxy-conn.js +++ b/lib/proxy-conn.js @@ -45,13 +45,16 @@ module.exports.create = function (deps, config) { conn.pipe(newConn); }); + // Listening for this largely to prevent uncaught exceptions. + conn.on('error', function (err) { + console.log('proxy client error', err); + }); newConn.on('error', function (err) { if (connected) { // Not sure how to report this to a user or a client. We can assume that some data // has already been exchanged, so we can't really be sure what we can send in addition // that wouldn't result in a parse error. console.log('proxy remote error', err); - conn.end(); } else { console.log('proxy connection error', err); if (decrypt) { @@ -62,10 +65,12 @@ module.exports.create = function (deps, config) { } }); - // Listening for this largely to prevent uncaught exceptions. - conn.on('error', function (err) { - console.log('proxy client error', err); - newConn.end(); + // Make sure that once one side closes, no I/O activity will happen on the other side. + conn.on('close', function () { + newConn.destroy(); + }); + newConn.on('close', function () { + conn.destroy(); }); }; };