From df71e9a6a5fe3a2dd4878169b213cf140eb42c24 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 4 Sep 2019 23:00:10 +0100 Subject: [PATCH] improved error handling for tcp bridge --- lib/tunnel.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/tunnel.js b/lib/tunnel.js index 7f9f4d8..f5bdf73 100644 --- a/lib/tunnel.js +++ b/lib/tunnel.js @@ -148,6 +148,7 @@ function Server(receiver, socket) { this.receiver.on('session_close', this.on_session_close.bind(this)); this.socket.on('data', this.on_socket_data.bind(this)); this.socket.on('end', this.on_socket_end.bind(this)); + this.socket.on('error', this.on_socket_error.bind(this)); } Server.prototype.on_message = function (context) { @@ -180,6 +181,11 @@ Server.prototype.on_socket_end = function (data) { process.nextTick(this.close.bind(this)); }; +Server.prototype.on_socket_error = function (error) { + console.error(error); + process.nextTick(this.close.bind(this)); +}; + Server.prototype.close = function () { this.receiver.close(); if (this.sender) {