diff --git a/src/unixTerminal.ts b/src/unixTerminal.ts index ce2e89ff..9f63e91f 100644 --- a/src/unixTerminal.ts +++ b/src/unixTerminal.ts @@ -189,6 +189,11 @@ export class UnixTerminal extends Terminal { // than using the `net.Socket`/`tty.WriteStream` wrappers which swallow the // errors and cause the thread to block indefinitely. fs.write(this._fd, data, (err, written) => { + // Requeue any partial writes + if (written < data.length) { + this._writeQueue.unshift(data.slice(written)); + } + if (err) { const errno = (err as any).errno; switch (errno) { @@ -216,11 +221,6 @@ export class UnixTerminal extends Terminal { } } - // Requeue any partial writes - if (written < data.length) { - this._writeQueue.unshift(data.slice(written)); - } - // Using `setImmediate` here appears to corrupt the data, this may be what // the interleaving/dropped data comment is about in Node.js' tty module: // https://github.com/nodejs/node/blob/4cac2b94bed4bf02810be054e8f63c0048c66564/lib/tty.js#L106C1-L111C34