ssh reconnection logic improvements - fixes #2705, fixes #761, fixes #2662

This commit is contained in:
Eugene Pankov 2020-07-05 12:47:32 +02:00
parent 7b4e6e8f3a
commit d0fe64355b
7 changed files with 36 additions and 25 deletions

View File

@ -161,7 +161,7 @@ export class SSHSession extends BaseSession {
} }
}) })
this.shell.on('end', () => { this.shell.on('end', e => {
this.logger.info('Shell session ended') this.logger.info('Shell session ended')
if (this.open) { if (this.open) {
this.destroy() this.destroy()

View File

@ -19,20 +19,21 @@
[(ngModel)]='connection.group', [(ngModel)]='connection.group',
) )
.form-group .d-flex
label Host .form-group
input.form-control( label Host
type='text', input.form-control(
[(ngModel)]='connection.host', type='text',
) [(ngModel)]='connection.host',
)
.form-group .form-group
label Port label Port
input.form-control( input.form-control(
type='number', type='number',
placeholder='22', placeholder='22',
[(ngModel)]='connection.port', [(ngModel)]='connection.port',
) )
.form-group .form-group
label Username label Username

View File

@ -6,9 +6,9 @@
i.fas.fa-circle.text-danger.mr-2(*ngIf='!session.open') 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}} 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') button.btn.btn-secondary((click)='showPortForwarding()', *ngIf='session.open')
i.fas.fa-plug i.fas.fa-plug
span Ports span Ports
button.btn.btn-info((click)='reconnect()', *ngIf='!session.open')
span Reconnect

View File

@ -95,6 +95,10 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
session.resize(this.size.columns, this.size.rows) 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`) this.write('\r\n' + colors.black.bgCyan(' SSH ') + ` Connecting to ${session.connection.host}\r\n`)
const spinner = new Spinner({ const spinner = new Spinner({
@ -149,8 +153,10 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
modal.session = this.session modal.session = this.session
} }
reconnect (): void { async reconnect (): Promise<void> {
this.initializeSession() this.session?.destroy()
await this.initializeSession()
this.session.releaseInitialDataBuffer()
} }
async canClose (): Promise<boolean> { async canClose (): Promise<boolean> {

View File

@ -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$.bufferTime(10).subscribe((datas) => {
this.session.output$.subscribe(data => { this.session.output$.subscribe(data => {
if (this.enablePassthrough) { if (this.enablePassthrough) {
@ -485,9 +485,11 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
} }
}) })
this.sessionCloseSubscription = this.session.closed$.subscribe(() => { if (destroyOnSessionClose) {
this.frontend.destroy() this.sessionCloseSubscription = this.session.closed$.subscribe(() => {
this.destroy() this.frontend.destroy()
}) this.destroy()
})
}
} }
} }

View File

@ -60,7 +60,7 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
}) })
) )
this.attachSessionHandlers() this.attachSessionHandlers(true)
} }
async getRecoveryToken (): Promise<any> { async getRecoveryToken (): Promise<any> {

View File

@ -73,6 +73,8 @@ export abstract class BaseSession {
this.open = false this.open = false
this.closed.next() this.closed.next()
this.destroyed.next() this.destroyed.next()
this.closed.complete()
this.destroyed.complete()
this.output.complete() this.output.complete()
this.binaryOutput.complete() this.binaryOutput.complete()
await this.gracefullyKillProcess() await this.gracefullyKillProcess()