improved error handling for TLS/TCP proxying

This commit is contained in:
tigerbot 2017-05-10 17:21:03 -06:00
parent 158c363c88
commit e24f9412dd
2 changed files with 22 additions and 0 deletions

View File

@ -94,6 +94,17 @@ module.exports.create = function (deps, config) {
});
// Not sure how to effectively report this to the user or client, but we need to listen
// for the event to prevent it from crashing us.
newConn.on('error', function (err) {
console.error('TCP forward connection error', err);
conn.end();
});
conn.on('error', function (err) {
console.error('TCP forward client error', err);
newConn.end();
});
newConn.pipe(conn);
conn.pipe(newConn);
};

View File

@ -147,6 +147,17 @@ module.exports.create = function (deps, config, netHandler) {
, remotePort: opts.port || extractSocketProp(socket, 'remotePort')
});
// Not sure how to effectively report this to the user or client, but we need to listen
// for the event to prevent it from crashing us.
newConn.on('error', function (err) {
console.error('TLS proxy connection error', err);
socket.end();
});
socket.on('error', function (err) {
console.error('TLS proxy client error', err);
newConn.end();
});
newConn.write(opts.firstChunk);
newConn.pipe(socket);
socket.pipe(newConn);