Skip to content

Commit

Permalink
dont try to resize if we invalidated the fd
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Sep 20, 2024
1 parent 30da8d8 commit f173e52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
19 changes: 19 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,25 @@ describe(
});
}));

test('resize after exit shouldn\'t throw', () => new Promise<void>((done, reject) => {
const pty = new Pty({
command: '/bin/echo',
args: ['hello'],
onExit: (err, exitCode) => {
try {
expect(err).toBeNull();
expect(exitCode).toBe(0);
expect(() => {
pty.resize({ rows: 60, cols: 100 });
}).not.toThrow();
done();
} catch (e) {
reject(e)
}
},
});
}));

test(
'ordering is correct',
() =>
Expand Down
10 changes: 7 additions & 3 deletions wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ExitResult = {
export class Pty {
#pty: RawPty;
#fd: number;
#fdEnded: boolean = false;
#socket: ReadStream;

read: Readable;
Expand Down Expand Up @@ -78,13 +79,12 @@ export class Pty {
this.write = userFacingWrite;

// catch end events
let handleCloseCalled = false;
const handleClose = () => {
if (handleCloseCalled) {
if (this.#fdEnded) {
return;
}

handleCloseCalled = true;
this.#fdEnded = true;
exitResult.then((result) => realExit(result.error, result.code));
userFacingRead.end();
};
Expand Down Expand Up @@ -122,6 +122,10 @@ export class Pty {
}

resize(size: Size) {
if (this.#fdEnded) {
return;
}

ptyResize(this.#fd, size);
}

Expand Down

0 comments on commit f173e52

Please sign in to comment.