From d0fe64355ba8dbf6eb4b1bdc7ef9f9e84c82360b Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 5 Jul 2020 12:47:32 +0200 Subject: [PATCH] ssh reconnection logic improvements - fixes #2705, fixes #761, fixes #2662 --- terminus-ssh/src/api.ts | 2 +- .../editConnectionModal.component.pug | 27 ++++++++++--------- .../src/components/sshTab.component.pug | 6 ++--- .../src/components/sshTab.component.ts | 10 +++++-- .../src/api/baseTerminalTab.component.ts | 12 +++++---- .../src/components/terminalTab.component.ts | 2 +- .../src/services/sessions.service.ts | 2 ++ 7 files changed, 36 insertions(+), 25 deletions(-) diff --git a/terminus-ssh/src/api.ts b/terminus-ssh/src/api.ts index 91a3365c..c2d3b296 100644 --- a/terminus-ssh/src/api.ts +++ b/terminus-ssh/src/api.ts @@ -161,7 +161,7 @@ export class SSHSession extends BaseSession { } }) - this.shell.on('end', () => { + this.shell.on('end', e => { this.logger.info('Shell session ended') if (this.open) { this.destroy() diff --git a/terminus-ssh/src/components/editConnectionModal.component.pug b/terminus-ssh/src/components/editConnectionModal.component.pug index 95251785..d353b5fb 100644 --- a/terminus-ssh/src/components/editConnectionModal.component.pug +++ b/terminus-ssh/src/components/editConnectionModal.component.pug @@ -19,20 +19,21 @@ [(ngModel)]='connection.group', ) - .form-group - label Host - input.form-control( - type='text', - [(ngModel)]='connection.host', - ) + .d-flex + .form-group + label Host + input.form-control( + type='text', + [(ngModel)]='connection.host', + ) - .form-group - label Port - input.form-control( - type='number', - placeholder='22', - [(ngModel)]='connection.port', - ) + .form-group + label Port + input.form-control( + type='number', + placeholder='22', + [(ngModel)]='connection.port', + ) .form-group label Username diff --git a/terminus-ssh/src/components/sshTab.component.pug b/terminus-ssh/src/components/sshTab.component.pug index 5e722086..8382e62d 100644 --- a/terminus-ssh/src/components/sshTab.component.pug +++ b/terminus-ssh/src/components/sshTab.component.pug @@ -6,9 +6,9 @@ i.fas.fa-circle.text-danger.mr-2(*ngIf='!session.open') strong.mr-auto(*ngIf='session') {{session.connection.user}}@{{session.connection.host}}:{{session.connection.port}} + button.btn.btn-secondary.mr-2((click)='reconnect()', [class.btn-info]='!session.open') + span Reconnect + button.btn.btn-secondary((click)='showPortForwarding()', *ngIf='session.open') i.fas.fa-plug span Ports - - button.btn.btn-info((click)='reconnect()', *ngIf='!session.open') - span Reconnect diff --git a/terminus-ssh/src/components/sshTab.component.ts b/terminus-ssh/src/components/sshTab.component.ts index 40b9bc32..bae253c1 100644 --- a/terminus-ssh/src/components/sshTab.component.ts +++ b/terminus-ssh/src/components/sshTab.component.ts @@ -95,6 +95,10 @@ export class SSHTabComponent extends BaseTerminalTabComponent { session.resize(this.size.columns, this.size.rows) }) + session.destroyed$.subscribe(() => { + this.write('\r\n' + colors.black.bgCyan(' SSH ') + ` ${session.connection.host}: session closed\r\n`) + }) + this.write('\r\n' + colors.black.bgCyan(' SSH ') + ` Connecting to ${session.connection.host}\r\n`) const spinner = new Spinner({ @@ -149,8 +153,10 @@ export class SSHTabComponent extends BaseTerminalTabComponent { modal.session = this.session } - reconnect (): void { - this.initializeSession() + async reconnect (): Promise { + this.session?.destroy() + await this.initializeSession() + this.session.releaseInitialDataBuffer() } async canClose (): Promise { diff --git a/terminus-terminal/src/api/baseTerminalTab.component.ts b/terminus-terminal/src/api/baseTerminalTab.component.ts index 48f5a0af..bb69e5bb 100644 --- a/terminus-terminal/src/api/baseTerminalTab.component.ts +++ b/terminus-terminal/src/api/baseTerminalTab.component.ts @@ -474,7 +474,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit ] } - protected attachSessionHandlers (): void { + protected attachSessionHandlers (destroyOnSessionClose = false): void { // this.session.output$.bufferTime(10).subscribe((datas) => { this.session.output$.subscribe(data => { if (this.enablePassthrough) { @@ -485,9 +485,11 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit } }) - this.sessionCloseSubscription = this.session.closed$.subscribe(() => { - this.frontend.destroy() - this.destroy() - }) + if (destroyOnSessionClose) { + this.sessionCloseSubscription = this.session.closed$.subscribe(() => { + this.frontend.destroy() + this.destroy() + }) + } } } diff --git a/terminus-terminal/src/components/terminalTab.component.ts b/terminus-terminal/src/components/terminalTab.component.ts index 9234bce3..5eaa1224 100644 --- a/terminus-terminal/src/components/terminalTab.component.ts +++ b/terminus-terminal/src/components/terminalTab.component.ts @@ -60,7 +60,7 @@ export class TerminalTabComponent extends BaseTerminalTabComponent { }) ) - this.attachSessionHandlers() + this.attachSessionHandlers(true) } async getRecoveryToken (): Promise { diff --git a/terminus-terminal/src/services/sessions.service.ts b/terminus-terminal/src/services/sessions.service.ts index 383b3459..687f4c32 100644 --- a/terminus-terminal/src/services/sessions.service.ts +++ b/terminus-terminal/src/services/sessions.service.ts @@ -73,6 +73,8 @@ export abstract class BaseSession { this.open = false this.closed.next() this.destroyed.next() + this.closed.complete() + this.destroyed.complete() this.output.complete() this.binaryOutput.complete() await this.gracefullyKillProcess()