tweaked proxy behavior on error/close

This commit is contained in:
tigerbot 2017-05-18 14:14:44 -06:00
parent aa28a72f3f
commit 5bbf57a57a
1 changed files with 10 additions and 5 deletions

View File

@ -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();
});
};
};