Repository navigation
fix: treat non-cluster SELECT failures during handshake as fatal - #2260
helmipradita wants to merge 1 commit into
Conversation
|
Thanks for the PR. Unfortunately this is a breaking change, so we can't take it. Today, if the connect-time The unhandled rejection reported in #1213 is already fixed: the error now goes to the redis.on("error", (err) => {
if (err.command?.name === "select") redis.disconnect();
}); |
Ah, totally fair point @PavelPashov! Apologies, I was so focused on the db fallback issue itself that I overlooked the backward-compat implications for existing proxy/custom setups and the retry loop side effect. Makes complete sense why keeping it non-fatal is necessary here, and thanks for pointing out the fail-fast workaround via the |
Fixes #1213.
Summary
When configuring
new Redis({ db: <invalid_or_out_of_range> }), the initial connection handshake sendsSELECT <db>viagetHandshakeCommands(). Previously, its error handler was:Because the error was swallowed without re-throwing,
sendHandshake()treated the command as handled and proceeded with the ready check. The client transitioned to"ready"status while running commands againstdb 0, even thoughredis.options.dbshowed the configured target DB. Any subsequent read or write command was executed against the wrong database silently.Fix
lib/redis/event_handler.ts, replace the silent error swallowing withhandleSelectError(self, err).ERR DB index is out of rangeorERR invalid DB index) are re-thrown, allowingconnectHandlerto enterrecoverFromFatalError(err), flush the queue, and triggerretryStrategy/ disconnection.select is not allowed in cluster mode, it continues to be emitted viasilentEmit("error", err)without throwing.Test
Added regression tests in
test/functional/connection.tsacross both RESP2 and RESP3:SELECTduring handshake causes connection failure (status === "end") and prevents"ready"from firing.SELECT is not allowed in cluster modecontinues to be tolerated and allows the client to become"ready".