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

unreliable proc.on('close') event #419

Open
justinmk opened this issue Oct 11, 2024 · 1 comment
Open

unreliable proc.on('close') event #419

justinmk opened this issue Oct 11, 2024 · 1 comment
Labels

Comments

@justinmk
Copy link
Member

justinmk commented Oct 11, 2024

This is a tracking issue for a potential issue noticed in #414 (comment)

Problem

proc.on('close') does not always trigger on nvim.quit(). Based on the failures demonstrated in #418, it appears that sometimes the child (nvim) does not close the stderr pipe:

    expect(received).toStrictEqual(expected) // deep equality

    - Expected  - 1
    + Received  + 1

      Object {
        "errors": 0,
    -   "stderrClosed": true,
    +   "stderrClosed": false,
        "stdoutClosed": true,
      }

      172 |     // TODO: 'close' event sometimes does not emit. #414
      173 |     proc.on('exit', () => {
    > 174 |       expect(r).toStrictEqual({
          |                 ^
      175 |         stdoutClosed: true,
      176 |         stderrClosed: true,
      177 |         errors: 0,

      at ChildProcess.toStrictEqual (src/attach/attach.test.ts:174:17)

Solution

@justinmk justinmk added the bug label Oct 11, 2024
@justinmk justinmk changed the title proc.on('close') is unreliable proc.on('close') event is unreliable Oct 11, 2024
@justinmk justinmk changed the title proc.on('close') event is unreliable unreliable proc.on('close') event Oct 11, 2024
@justinmk
Copy link
Member Author

patch to demo the issue, from #418

diff --git a/packages/neovim/src/attach/attach.test.ts b/packages/neovim/src/attach/attach.test.ts
index 70d16597..4f0c6942 100644
--- a/packages/neovim/src/attach/attach.test.ts
+++ b/packages/neovim/src/attach/attach.test.ts
@@ -154,14 +154,38 @@ describe('Nvim API', () => {
     expect(newLines).toEqual(['line1', 'line2']);
   });
 
-  it('emits "disconnect" after quit', done => {
+  it.only('emits "disconnect" after quit', done => {
     const disconnectMock = jest.fn();
     nvim.on('disconnect', disconnectMock);
 
     nvim.quit();
 
+    const r = {
+      stdoutClosed: false,
+      stderrClosed: false,
+      errors: 0,
+    };
+    proc.stdout.on('close', () => {
+      r.stdoutClosed = true;
+    });
+    proc.stderr.on('close', () => {
+      r.stderrClosed = true;
+    });
+    proc.on('error', () => {
+      r.errors = r.errors + 1;
+    });
+
     // TODO: 'close' event sometimes does not emit. #414
     proc.on('exit', () => {
+      expect(r).toStrictEqual({
+        stdoutClosed: true,
+        stderrClosed: true,
+        errors: 0,
+      });
+      done();
+    });
+
+    proc.on('close', () => {
       expect(disconnectMock).toHaveBeenCalledTimes(1);
       done();
     });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant