From 9ea260f0f9a3aba90c0c62ade443c23d5c44ab31 Mon Sep 17 00:00:00 2001 From: Nikolay Karadzhov Date: Wed, 21 May 2025 11:38:29 +0300 Subject: [PATCH] fix(handshake): ignore errors on client.setinfo (#2969) As per the documentation (https://redis.io/docs/latest/commands/client-setinfo): Client libraries are expected to pipeline this command after authentication on all connections and ignore failures since they could be connected to an older version that doesn't support them. Turns out different versions of redis server return different errors, so its better to catch all. fixes #2968 --- packages/client/lib/client/index.ts | 26 +++++++++----------------- packages/client/lib/errors.ts | 6 +----- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/packages/client/lib/client/index.ts b/packages/client/lib/client/index.ts index 8d98aa8ed2..a446ad8e75 100644 --- a/packages/client/lib/client/index.ts +++ b/packages/client/lib/client/index.ts @@ -4,7 +4,7 @@ import { BasicAuth, CredentialsError, CredentialsProvider, StreamingCredentialsP import RedisCommandsQueue, { CommandOptions } from './commands-queue'; import { EventEmitter } from 'node:events'; import { attachConfig, functionArgumentsPrefix, getTransformReply, scriptArgumentsPrefix } from '../commander'; -import { ClientClosedError, ClientOfflineError, DisconnectsClientError, SimpleError, WatchError } from '../errors'; +import { ClientClosedError, ClientOfflineError, DisconnectsClientError, WatchError } from '../errors'; import { URL } from 'node:url'; import { TcpSocketConnectOpts } from 'node:net'; import { PUBSUB_TYPE, PubSubType, PubSubListener, PubSubTypeListeners, ChannelListeners } from './pub-sub'; @@ -626,14 +626,10 @@ export default class RedisClient< if (!this.#options?.disableClientInfo) { commands.push({ cmd: ['CLIENT', 'SETINFO', 'LIB-VER', version], - errorHandler: (err: Error) => { - // Only throw if not a SimpleError - unknown subcommand - // Client libraries are expected to ignore failures - // of type SimpleError - unknown subcommand, which are - // expected from older servers ( < v7 ) - if (!(err instanceof SimpleError) || !err.isUnknownSubcommand()) { - throw err; - } + errorHandler: () => { + // Client libraries are expected to pipeline this command + // after authentication on all connections and ignore failures + // since they could be connected to an older version that doesn't support them. } }); @@ -646,14 +642,10 @@ export default class RedisClient< ? `node-redis(${this.#options.clientInfoTag})` : 'node-redis' ], - errorHandler: (err: Error) => { - // Only throw if not a SimpleError - unknown subcommand - // Client libraries are expected to ignore failures - // of type SimpleError - unknown subcommand, which are - // expected from older servers ( < v7 ) - if (!(err instanceof SimpleError) || !err.isUnknownSubcommand()) { - throw err; - } + errorHandler: () => { + // Client libraries are expected to pipeline this command + // after authentication on all connections and ignore failures + // since they could be connected to an older version that doesn't support them. } }); } diff --git a/packages/client/lib/errors.ts b/packages/client/lib/errors.ts index 4f05f62ac4..db37ec1a9b 100644 --- a/packages/client/lib/errors.ts +++ b/packages/client/lib/errors.ts @@ -70,11 +70,7 @@ export class ErrorReply extends Error { } } -export class SimpleError extends ErrorReply { - isUnknownSubcommand(): boolean { - return this.message.toLowerCase().indexOf('err unknown subcommand') !== -1; - } -} +export class SimpleError extends ErrorReply {} export class BlobError extends ErrorReply {}