Permalink
Browse files

Tunnel: Make sure error is returned if there was any when establishin…

…g connection.
  • Loading branch information...
1 parent b6b654f commit 6d0c8315124a50489cbed8d7d462b238331e4bb6 @tomas tomas committed Mar 6, 2013
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/agent/tunnel.js
View
@@ -24,6 +24,7 @@ var Tunnel = function(local_port, remote_host, remote_port){
this.local_socket = null;
this.remote_socket = null;
this.status = null;
+ this.last_error = null;
this.log = function(str){
logger.debug('[tunnel] ' + str);
@@ -40,7 +41,7 @@ var Tunnel = function(local_port, remote_host, remote_port){
this.closed = function(err){
if (this.status === 'closed') return;
this.status = 'closed';
- this.emit('closed', err);
+ this.emit('closed', err || this.last_error);
};
this.opened = function(){
@@ -116,12 +117,14 @@ var Tunnel = function(local_port, remote_host, remote_port){
local_socket.on("error", function(e) {
self.log("Local socket error: " + e.code);
// local_socket.end();
+ self.last_error = e;
remote_socket.end(e.code); // sends and ends
});
// if this happens then the connection was never made
remote_socket.on("error", function(e) {
self.log("Remote socket error: " + e.code);
+ self.last_error = e;
remote_socket.destroy();
});

0 comments on commit 6d0c831

Please sign in to comment.