Skip to content

Commit

Permalink
Merge pull request #164 from Tyriar/163_high_sierra_issue
Browse files Browse the repository at this point in the history
Workaround socket not being closed properly on High Sierra
  • Loading branch information
Tyriar authored Dec 9, 2017
2 parents ba15d28 + 423cad1 commit 50adadc
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/unixTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const pty = require(path.join('..', 'build', 'Release', 'pty.node'));

const DEFAULT_FILE = 'sh';
const DEFAULT_NAME = 'xterm';
const DESTROY_SOCKET_TIMEOUT_MS = 200;

export class UnixTerminal extends Terminal {
protected _fd: number;
Expand Down Expand Up @@ -74,9 +75,24 @@ export class UnixTerminal extends Terminal {
// XXX Sometimes a data event is emitted after exit. Wait til socket is
// destroyed.
if (!this._emittedClose) {
if (this._boundClose) return;
if (this._boundClose) {
return;
}
this._boundClose = true;
this.once('close', () => this.emit('exit', code, signal));
// From macOS High Sierra 10.13.2 sometimes the socket never gets
// closed. A timeout is applied here to avoid the terminal never being
// destroyed when this occurs.
let timeout = setTimeout(() => {
timeout = null;
// Destroying the socket now will cause the close event to fire
this._socket.destroy();
}, DESTROY_SOCKET_TIMEOUT_MS);
this.once('close', () => {
if (timeout !== null) {
clearTimeout(timeout);
}
this.emit('exit', code, signal);
});
return;
}
this.emit('exit', code, signal);
Expand Down

0 comments on commit 50adadc

Please sign in to comment.