Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

NOAUTH Authentication required #20

Open
andrei-markeev opened this issue Sep 22, 2021 · 3 comments
Open

NOAUTH Authentication required #20

andrei-markeev opened this issue Sep 22, 2021 · 3 comments

Comments

@andrei-markeev
Copy link
Contributor

andrei-markeev commented Sep 22, 2021

Environment

  • Node version: v14.16.0
  • Redis Server version: 6.0.14
  • Redis protocol version: 2
  • Camaro Redis version: 2.4.0

Describe the bug

From time to time, I'm getting this error:

(node:5876) UnhandledPromiseRejectionWarning:
    Redis Reply Error: NOAUTH Authentication required.
        at Parser.parseSimpleError (C:\home\site\wwwroot\deps.js:382:14)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)

To Reproduce

Code to reproduce the behavior:

const { ClientV2: Client } = require('@camaro/redis')
const client = new Client({
    host: "<remote redis server host>",
    password: "testpass"
});

async function test() {
    await client.SET('bar', 'bar')
    const reply = await client.GET('bar')
    console.log(reply) // 'bar'
}

test().then(() => process.exit(0));

Additional context

I think, what happens is:

  1. I initialize the client - it starts connecting to the Redis server
  2. I start doing my stuff, and run some redis commands (before connection is established) - these go to the buffer
  3. Connection to server is established, authentication command is issued
  4. Client starts sending the commands to the server - but first commands are those from the buffer

It doesn't happen always, so probably it depends on the connection to redis server. Also, I am using SSL connection, SSL handshake also takes time.

@andrei-markeev
Copy link
Contributor Author

andrei-markeev commented Sep 26, 2021

some additional information:

  1. I tried adding a delay before sending commands, but that didn't help, so my assumption above is probably incorrect
  2. I think it might be related to the reconnects, but I am not sure
  3. I am now trying to periodically send PING command so that connection doesn't idle out (I am using Azure Redis Cache, and it is configured to 10 minutes idle timeout)

@andrei-markeev
Copy link
Contributor Author

Just an update: adding PING didn't help, still getting same error from time to time (couple times per day).
NOAUTH error always seems to happen on the first command sent to redis (although cannot tell with 100% certainty because stack trace is not showing where the error originates).

@andrei-markeev
Copy link
Contributor Author

andrei-markeev commented Oct 6, 2021

It seems the solution is, after all, to wait until the client connects and initializes. Maybe when I tried to solve this problem by adding a delay, delay was not big enough (it was 600ms).

Currently, I am using the following function to connect to Redis:

export function connectToCache() {
    return new Promise((resolve, reject) => {
            let connected = false;
            const client = new ClientV2({ ... });
            client.on("error", (e) => {
                if (connected)
                    console.error("Redis error", e);
                else
                    reject(e);
            });
            client.on("connect", () => {
                connected = true;
                resolve(client)
            });
    });
}

usage is like this:

const client = await connectToCache();
// do stuff with client

and the "NOAUTH" error doesn't happen anymore for me.

Even though the problem is now solved for me, I still think this issue needs to be addressed, since currently it is quite easy to use the client in incorrect way and start sending commands without waiting the client to connect.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant