Jwt #142

Closed
micoli wants to merge 129 commits from jwt into master
Showing only changes of commit 509841104b - Show all commits
+10 -5
View File
@@ -87,13 +87,13 @@ TunnelCluster.prototype.open = function() {
}); });
function conn_local() { function conn_local() {
debug('connecting locally to %s:%d', local_host, local_port);
if (remote.destroyed) { if (remote.destroyed) {
debug('remote destroyed');
self.emit('dead'); self.emit('dead');
return; return;
} }
debug('connecting locally to %s:%d', local_host, local_port);
remote.pause(); remote.pause();
// connection to local http server // connection to local http server
@@ -103,19 +103,24 @@ TunnelCluster.prototype.open = function() {
}); });
function remote_close() { function remote_close() {
debug('remote close');
self.emit('dead'); self.emit('dead');
local.end(); local.end();
}; };
remote.once('close', remote_close); remote.once('close', remote_close);
local.on('error', function(err) { // TODO some languages have single threaded servers which makes opening up
// multiple local connections impossible. We need a smarter way to scale
// and adjust for such instances to avoid beating on the door of the server
local.once('error', function(err) {
debug('local error %s', err.message);
local.end(); local.end();
remote.removeListener('close', remote_close); remote.removeListener('close', remote_close);
if (err.code !== 'ECONNREFUSED') { if (err.code !== 'ECONNREFUSED') {
return local.emit('error', err); return remove.end();
} }
// retrying connection to local server // retrying connection to local server
@@ -146,8 +151,8 @@ TunnelCluster.prototype.open = function() {
// tunnel is considered open when remote connects // tunnel is considered open when remote connects
remote.once('connect', function() { remote.once('connect', function() {
self.emit('open', remote); self.emit('open', remote);
conn_local();
}); });
remote.once('connect', conn_local);
}; };
var Tunnel = function(opt) { var Tunnel = function(opt) {