Skip to content

Reject multi.exec() promise with ClientClosedError after client disconnect #2293

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/client/lib/client/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,19 @@ describe('Client', () => {
);
}, GLOBAL.SERVERS.OPEN);

testUtils.testWithClient('should reject the whole chain upon client disconnect', async client => {
await client.disconnect();

return assert.rejects(
client.multi()
.ping()
.set('key', 'value')
.get('key')
.exec(),
ClientClosedError
);
}, GLOBAL.SERVERS.OPEN);

testUtils.testWithClient('with script', async client => {
assert.deepEqual(
await client.multi()
Expand Down
4 changes: 4 additions & 0 deletions packages/client/lib/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ export default class RedisClient<
selectedDB?: number,
chainId?: symbol
): Promise<Array<RedisCommandRawReply>> {
if (!this.#socket.isOpen) {
return Promise.reject(new ClientClosedError());
}

const promise = Promise.all(
commands.map(({ args }) => {
return this.#queue.addCommand(args, { chainId });
Expand Down