Skip to content

Socket options object is modified #2851

Open
@adoeppner

Description

@adoeppner

Description

We have a service that is connected to multiple Redis servers. We noticed that after a connection loss, some of the connections suddenly started throwing weird auth errors.

WRONGPASS invalid username-password pair or user is disabled.

After a bit of digging we discovered that we have some default options that we use for each of our redis connections, and this object reference is overwritten by each redis client we instantiate.

A simple setup to run into the problem immediately looks like this, but if you connect to redis directly after instantiating the redis client, you won't notice the error until the client tries to reconnect.

const options = {
    socket: {
        reconnectStrategy: () => 10000
    }
}

const client1 = createClient({ url: "redis://:server1pass@localhost:2345", ...options })
const client2 = createClient({ url: "redis://:server2pass@localhost:2346", ...options })

client1.on("error", (err) => logger.error("Redis client1 error:", err))
client2.on("error", (err) => logger.error("Redis client2 error:", err))

await client1.connect()
await client2.connect()

You could argue this is done by design but it feels a bit strange and cost us a few hours of debugging. Code which leads to this is here:

https://github.com/redis/node-redis/blob/master/packages/client/lib/client/index.ts#L248

Node.js Version

v20.15.1

Redis Server Version

7.2.5

Node Redis Version

4.6.7

Platform

any

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions