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')
if (this.open) {
this.destroy()

View File

@ -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

View File

@ -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

View File

@ -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<void> {
this.session?.destroy()
await this.initializeSession()
this.session.releaseInitialDataBuffer()
}
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$.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()
})
}
}
}

View File

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

View File

@ -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()