Open justinmk opened 1 month ago
patch to demo the issue, from https://github.com/neovim/node-client/pull/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();
});
This is a tracking issue for a potential issue noticed in https://github.com/neovim/node-client/pull/414#discussion_r1796637402
Problem
proc.on('close')
does not always trigger onnvim.quit()
. Based on the failures demonstrated in https://github.com/neovim/node-client/pull/418, it appears that sometimes the child (nvim
) does not close the stderr pipe:Solution
proc.on('close')
is unreliable.proc.on('exit')
as a workaround.but, forcing
fclose(stderr)
does not pass the tests in this PR. Nor does addingfclose(stderr)
anywhere else AFAICT.