Skip to content

Commit

Permalink
3.2.1 dont try to resize if we invalidated the fd (#43)
Browse files Browse the repository at this point in the history
`ioctl TIOCSWINSZ failed: Bad file descriptor (os error 9)` makes me sad

- js owns the fd so its safe to mark the fd as dead after the read
stream derived from the pty fd ends
- after the fd is dead, dont try to resize
  • Loading branch information
jackyzha0 authored Sep 20, 2024
1 parent 30da8d8 commit 17d97e7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@replit/ruspty-darwin-arm64",
"version": "3.0.5",
"version": "3.2.1",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@replit/ruspty-darwin-x64",
"version": "3.0.5",
"version": "3.2.1",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@replit/ruspty-linux-x64-gnu",
"version": "3.0.5",
"version": "3.2.1",
"os": [
"linux"
],
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@replit/ruspty",
"version": "3.2.0",
"version": "3.2.1",
"main": "dist/wrapper.js",
"types": "dist/wrapper.d.ts",
"author": "Szymon Kaliski <[email protected]>",
Expand Down
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 17d97e7

Please sign in to comment.