Skip to content

Commit 9ea260f

Browse files
authored
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
1 parent b8acbce commit 9ea260f

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

packages/client/lib/client/index.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BasicAuth, CredentialsError, CredentialsProvider, StreamingCredentialsP
44
import RedisCommandsQueue, { CommandOptions } from './commands-queue';
55
import { EventEmitter } from 'node:events';
66
import { attachConfig, functionArgumentsPrefix, getTransformReply, scriptArgumentsPrefix } from '../commander';
7-
import { ClientClosedError, ClientOfflineError, DisconnectsClientError, SimpleError, WatchError } from '../errors';
7+
import { ClientClosedError, ClientOfflineError, DisconnectsClientError, WatchError } from '../errors';
88
import { URL } from 'node:url';
99
import { TcpSocketConnectOpts } from 'node:net';
1010
import { PUBSUB_TYPE, PubSubType, PubSubListener, PubSubTypeListeners, ChannelListeners } from './pub-sub';
@@ -626,14 +626,10 @@ export default class RedisClient<
626626
if (!this.#options?.disableClientInfo) {
627627
commands.push({
628628
cmd: ['CLIENT', 'SETINFO', 'LIB-VER', version],
629-
errorHandler: (err: Error) => {
630-
// Only throw if not a SimpleError - unknown subcommand
631-
// Client libraries are expected to ignore failures
632-
// of type SimpleError - unknown subcommand, which are
633-
// expected from older servers ( < v7 )
634-
if (!(err instanceof SimpleError) || !err.isUnknownSubcommand()) {
635-
throw err;
636-
}
629+
errorHandler: () => {
630+
// Client libraries are expected to pipeline this command
631+
// after authentication on all connections and ignore failures
632+
// since they could be connected to an older version that doesn't support them.
637633
}
638634
});
639635

@@ -646,14 +642,10 @@ export default class RedisClient<
646642
? `node-redis(${this.#options.clientInfoTag})`
647643
: 'node-redis'
648644
],
649-
errorHandler: (err: Error) => {
650-
// Only throw if not a SimpleError - unknown subcommand
651-
// Client libraries are expected to ignore failures
652-
// of type SimpleError - unknown subcommand, which are
653-
// expected from older servers ( < v7 )
654-
if (!(err instanceof SimpleError) || !err.isUnknownSubcommand()) {
655-
throw err;
656-
}
645+
errorHandler: () => {
646+
// Client libraries are expected to pipeline this command
647+
// after authentication on all connections and ignore failures
648+
// since they could be connected to an older version that doesn't support them.
657649
}
658650
});
659651
}

packages/client/lib/errors.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ export class ErrorReply extends Error {
7070
}
7171
}
7272

73-
export class SimpleError extends ErrorReply {
74-
isUnknownSubcommand(): boolean {
75-
return this.message.toLowerCase().indexOf('err unknown subcommand') !== -1;
76-
}
77-
}
73+
export class SimpleError extends ErrorReply {}
7874

7975
export class BlobError extends ErrorReply {}
8076

0 commit comments

Comments
 (0)