Skip to content

Commit

Permalink
fixed #6263, fixed #7460 - ssh: handle MaxSessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Nov 17, 2022
1 parent c7eb193 commit 0f0f61f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
38 changes: 21 additions & 17 deletions tabby-ssh/src/components/sshTab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
super.ngOnInit()
}

async setupOneSession (injector: Injector, profile: SSHProfile): Promise<SSHSession> {
async setupOneSession (injector: Injector, profile: SSHProfile, multiplex = true): Promise<SSHSession> {
let session = await this.sshMultiplexer.getSession(profile)
if (!session || !profile.options.reuseSession) {
if (!multiplex || !session || !profile.options.reuseSession) {
session = new SSHSession(injector, profile)

if (profile.options.jumpHost) {
Expand Down Expand Up @@ -146,11 +146,8 @@ export class SSHTabComponent extends BaseTerminalTabComponent {

try {
await session.start()
} finally {
this.stopSpinner()
} catch (e) {
this.stopSpinner()
this.write(colors.black.bgRed(' X ') + ' ' + colors.red(e.message) + '\r\n')
return session
}

this.sshMultiplexer.addSession(session)
Expand Down Expand Up @@ -186,21 +183,14 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
super.attachSessionHandlers()
}

async initializeSession (): Promise<void> {
this.reconnectOffered = false
private async initializeSessionMaybeMultiplex (multiplex = true): Promise<void> {
if (!this.profile) {
this.logger.error('No SSH connection info supplied')
return
}

try {
this.sshSession = await this.setupOneSession(this.injector, this.profile)
} catch (e) {
this.write(colors.black.bgRed(' X ') + ' ' + colors.red(e.message) + '\r\n')
return
throw new Error('No SSH connection info supplied')
}

this.sshSession = await this.setupOneSession(this.injector, this.profile, multiplex)
const session = new SSHShellSession(this.injector, this.sshSession, this.profile)

this.setSession(session)
this.attachSessionHandler(session.serviceMessage$, msg => {
msg = msg.replace(/\n/g, '\r\n ')
Expand All @@ -212,6 +202,20 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
this.session?.resize(this.size.columns, this.size.rows)
}

async initializeSession (): Promise<void> {
this.reconnectOffered = false
try {
await this.initializeSessionMaybeMultiplex(true)
} catch {
try {
await this.initializeSessionMaybeMultiplex(false)
} catch (e) {
this.write(colors.black.bgRed(' X ') + ' ' + colors.red(e.message) + '\r\n')
return
}
}
}

async getRecoveryToken (options?: GetRecoveryTokenOptions): Promise<RecoveryToken> {
return {
type: 'app:ssh-tab',
Expand Down
4 changes: 3 additions & 1 deletion tabby-ssh/src/services/sshMultiplexer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export class SSHMultiplexerService {
const key = await this.getMultiplexerKey(session.profile)
this.sessions.set(key, session)
session.willDestroy$.subscribe(() => {
this.sessions.delete(key)
if (this.sessions.get(key) === session) {
this.sessions.delete(key)
}
})
}

Expand Down
4 changes: 1 addition & 3 deletions tabby-ssh/src/session/shell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Observable, Subject } from 'rxjs'
import colors from 'ansi-colors'
import stripAnsi from 'strip-ansi'
import { ClientChannel } from 'ssh2'
import { Injector } from '@angular/core'
Expand Down Expand Up @@ -41,11 +40,10 @@ export class SSHShellSession extends BaseSession {
try {
this.shell = await this.ssh.openShellChannel({ x11: this.profile.options.x11 ?? false })
} catch (err) {
this.emitServiceMessage(colors.bgRed.black(' X ') + ` Remote rejected opening a shell channel: ${err}`)
if (err.toString().includes('Unable to request X11')) {
this.emitServiceMessage(' Make sure `xauth` is installed on the remote side')
}
return
throw new Error(`Remote rejected opening a shell channel: ${err}`)
}

this.open = true
Expand Down

0 comments on commit 0f0f61f

Please sign in to comment.