Skip to content

Commit

Permalink
Add temporary fix for write after end error
Browse files Browse the repository at this point in the history
  • Loading branch information
w1am committed Feb 26, 2024
1 parent 6444cad commit 46ead15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/__test__/extra/write-after-end.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @jest-environment ./src/__test__/utils/enableVersionCheck.ts */
/* eslint-disable @typescript-eslint/no-explicit-any */

import {
createTestNode,
Expand Down Expand Up @@ -31,11 +30,11 @@ const neverEndingEvents: Array<EventData> = (function* neverEndingEvents() {
},
});
}
})() as any;
})() as never;

// neverEndingEvents really is an array...
const isArray = Array.isArray;
Array.isArray = (arg): arg is any[] => {
Array.isArray = (arg): arg is never[] => {
if (isArray(arg)) return true;
if (arg === neverEndingEvents) return true;
return false;
Expand All @@ -62,22 +61,20 @@ describe("write after end", () => {
credentials: { username: "admin", password: "changeit" },
});

const neverEndingAppend = client.appendToStream(
STREAM_NAME,
neverEndingEvents,
{
const neverEndingAppend = client
.appendToStream(STREAM_NAME, neverEndingEvents, {
// credentials enforces classic append
credentials: { username: "admin", password: "changeit" },
deadline: Infinity,
}
).catch(err => err);
})
.catch((err) => err);

// let the write get started
await delay(1);

await node.killNode(node.endpoints[0]);

const error = await neverEndingAppend
const error = await neverEndingAppend;
expect(error).toBeInstanceOf(UnavailableError);

// wait for any unhandled rejections
Expand Down
7 changes: 7 additions & 0 deletions src/utils/CommandError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@ export const convertToCommandError = (error: Error): CommandError | Error => {
}
}

// This is a temporary workaround for a bug in node js. Must be removed when the bug is fixed.
// https://github.com/grpc/grpc-node/issues/2502
// and https://github.com/nodejs/node/issues/49147
if (error.details.includes("write after end")) {
return new UnavailableError(error);
}

return new UnknownError(error);
};

Expand Down

0 comments on commit 46ead15

Please sign in to comment.