diff --git a/tabby-ssh/src/session/shell.ts b/tabby-ssh/src/session/shell.ts index b302c63b7..cd986702b 100644 --- a/tabby-ssh/src/session/shell.ts +++ b/tabby-ssh/src/session/shell.ts @@ -14,6 +14,7 @@ export class SSHShellSession extends BaseSession { get serviceMessage$ (): Observable { return this.serviceMessage } private serviceMessage = new Subject() private ssh: SSHSession|null + private writing: Promise = Promise.resolve() constructor ( injector: Injector, @@ -98,9 +99,15 @@ export class SSHShellSession extends BaseSession { } write (data: Buffer): void { - if (this.shell) { - this.shell.write(new Uint8Array(data)) + const shell = this.shell + if (!shell) { + return } + // Each native write is its own async task; unless chained they can + // reach the channel out of order (corrupts ZMODEM uploads). + this.writing = this.writing + .then(() => shell.write(new Uint8Array(data))) + .catch(error => this.logger.debug('Shell write failed', error)) } kill (_signal?: string): void { diff --git a/tabby-terminal/src/features/zmodem.ts b/tabby-terminal/src/features/zmodem.ts index c9595fbc8..08644cd07 100644 --- a/tabby-terminal/src/features/zmodem.ts +++ b/tabby-terminal/src/features/zmodem.ts @@ -11,7 +11,6 @@ const SPACER = ' ' class ZModemMiddleware extends SessionMiddleware { private sentry: ZModem.Sentry - private writeQueue: Promise = Promise.resolve() private isActive = false private logger: Logger private activeSession: any = null @@ -62,12 +61,7 @@ class ZModemMiddleware extends SessionMiddleware { this.outputToTerminal.next(Buffer.from(data)) } }, - sender: data => { - const buf = Buffer.from(data) - this.writeQueue = this.writeQueue.then(async () => { - this.outputToSession.next(buf) - }) - return this.writeQueue }, + sender: data => this.outputToSession.next(Buffer.from(data)), on_detect: async detection => { if ((await this.platform.showMessageBox({ type: 'warning',