Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gemini-testing/ssh-tun
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil Kolesnikov committed Dec 19, 2019
2 parents 79b1dc4 + 6ed72b9 commit 3603593
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var Tunnel = inherit(EventEmitter, {
this._identity = opts.identity;

this._activityWatcher = opts.inactivityTimeout > 0 ?
new ActivityWatcher(opts.inactivityTimeout, this.close.bind(this)) : null;
new ActivityWatcher(opts.inactivityTimeout, this.close.bind(this, 'inactivity timeout')) : null;
},

/**
Expand Down Expand Up @@ -88,17 +88,22 @@ var Tunnel = inherit(EventEmitter, {
* Closes connection. If no connection established does nothing
* @returns {Promise}
*/
close: function () {
close: function (reason) {
reason = reason || 'intentional close';

if (!this._tunnel) {
return q();
}

var _this = this;

debug('closing tunnel: ' + reason);
this._tunnel.kill('SIGTERM');

return this._closeDeferred.promise.timeout(3000).fail(function () {
debug('killing tunnel due to termination timeout, original reason: ' + reason);
_this._tunnel.kill('SIGKILL');

return _this._closeTunnel(-1);
});
},
Expand All @@ -112,6 +117,10 @@ var Tunnel = inherit(EventEmitter, {
this._activityWatcher.update();
}

if (this.connected) {
return;
}

if (/success/.test(data)) {
if (!this._activityWatcher) {
this._tunnel.stderr.removeAllListeners('data');
Expand All @@ -120,7 +129,7 @@ var Tunnel = inherit(EventEmitter, {
return this._resolveTunnel();
}

if (!this.connected && /failed/.test(data)) {
if (/failed/.test(data)) {
return this._rejectTunnel();
}
},
Expand Down

0 comments on commit 3603593

Please sign in to comment.