Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-pty loses output with >4kb output in a fast program #726

Open
jackyzha0 opened this issue Oct 29, 2024 · 0 comments
Open

node-pty loses output with >4kb output in a fast program #726

jackyzha0 opened this issue Oct 29, 2024 · 0 comments

Comments

@jackyzha0
Copy link

Hey! I noticed that sometimes output isn't fully flushed if theres more than 4kb of output and the program exits really quickly

I suspect that this is due to the kernel buffering output between the controller and user fd but not 100% sure. I tried to minimize this in our own implementation of node-pty by polling for both TIOCINQ and TIOCOUTQ to be 0 on both fds before calling the exit handler but we still see it (although much more rarely)

Curious if you have thoughts here or if I'm just holding it wrong

reproduction

import * as pty from "node-pty";
import { describe, test, vi, expect } from "vitest";

describe("nodepty reliability", { repeats: 100 }, () => {
  test("doesnt miss large output from fast commands", async () => {
    const payload = `hello`.repeat(4096);
    let buffer = "";
    const onExit = vi.fn();

    const ptyProcess = pty.spawn("/bin/echo", ["-n", payload], {});
    ptyProcess.onExit(onExit);

    ptyProcess.onData((data) => {
      buffer = buffer + data;
    });

    await vi.waitFor(() => expect(onExit).toHaveBeenCalledTimes(1));
    expect(onExit).toHaveBeenCalledWith({ exitCode: 0, signal: 0 });
    expect(buffer.toString().length).toBe(payload.length);
  });
});

surprisingly, this is fine on MacOS but fails on linux

~/workspace$ uname -a
Linux 33c149080877 6.2.16 #1-NixOS SMP PREEMPT_DYNAMIC Tue Jan  1 00:00:00 UTC 1980 x86_64 GNU/Linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant