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

fix: select db in cluster mode causes unhandled errors #1311

Merged
merged 1 commit into from
Mar 27, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/redis/event_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export function connectHandler(self) {
}

if (self.condition.select) {
self.select(self.condition.select);
self.select(self.condition.select).catch((err) => {
// If the node is in cluster mode, select is disallowed.
// In this case, reconnect won't help.
self.silentEmit("error", err);
});
}

if (!self.options.enableReadyCheck) {
Expand Down
18 changes: 18 additions & 0 deletions test/functional/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,22 @@ describe("disconnection", function () {
done();
});
});

it("emits an error if select is not allowed", function (done) {
const errMessage = "select is not allowed";
const node = new MockServer(30001, function (argv) {
if (argv[0] === "select") {
return new Error(errMessage);
}
});
const redis = new Redis({ port: 30001, db: 2 });
redis.on("error", (err) => {
if (err.message === errMessage) {
redis.disconnect();
node.disconnect(() => {
done();
});
}
});
});
});