redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.4k stars 1.2k forks source link

Ones again - NOAUTH Authentication required #1399

Closed fulvi0 closed 3 years ago

fulvi0 commented 3 years ago

Hi, I'm facing an issue that has been reported multiples times, sorry for opening another ticket, but I tried multiples ways, but still getting the same error of NOAUTH Authentication required.

versions

I creating a redisClient like:


const Redis = require('ioredis');
...
const { redis } = require('../config/config');

const createClient = () => {
  try {
    let redisClient;
    redisClient = new Redis({
      port: redis.redisPort,
      host: redis.redisHost,
      family: 4,
      password: redis.redisPass,
    });
    return redisClient;
  } catch (error) {
    logger.log('error', modules.ServiceModules.REDIS, "Error creating Redis Client", `${error}`);
  }
};

module.exports = {
  createClient,
};

And getting the following error.

{"timestamp":"2021-08-01T00:22:05.375Z","level":"info","hostname":"20a9165bfd1b","service":"BACKEND","module":"EXPRESS","versionService":"1.0.0","versionModule":"1.0","operation":"INITIALIZING SERVER","description":"","operationChannel":"SERVER","entity":"EXPRESS","message":"Server is already listening, on PORT: 4602; and redis pass is = superapassword"}
[ioredis] Unhandled error event: ReplyError: NOAUTH Authentication required.
    at parseError (/usr/src/app/node_modules/redis-parser/lib/parser.js:179:12)
    at parseType (/usr/src/app/node_modules/redis-parser/lib/parser.js:302:14)

Note: I double-check the password and tested using a GUI Client, and the password is the correct one.

Thank u!

luin commented 3 years ago

It's not easy to tell the reason from the code you posted. The error may be returned from a different client. I'd create a minimal reproducible example to see what is the root cause.

fulvi0 commented 3 years ago

Hi @luin thx for the quick response.

I tried a different approach, by removing the requirepass from the Redis configuration, and this time its connection to the instance.

[WARN] This Redis server's `default` user does not require a password, but a password was supplied

Still facing the issue with AUTH on.

luin commented 3 years ago

Still, it's hard to say whether the error came from a different client or not. So it's hard to debug without a reproducible example. You may want to specify connectionName in new Redis and run client list on redis-cli to see if the instance has connected to the server or not because if the password is wrong, it won't appear in the list. Another possibility is the host/port doesn't match.

fulvi0 commented 3 years ago

Hi @luin ,

 redisClient = new Redis({
      port: redis.redisPort,
      host: redis.redisHost,
      family: 4,
      // password: redis.redisPass,
      password: "superpassword",
      connectionName: "hi",
    });
127.0.0.1:6379> client list
id=1568 addr=127.0.0.1:44042 laddr=127.0.0.1:6379 fd=7 name= age=3245 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=40928 argv-mem=10 obl=0 oll=0 omem=0 tot-mem=61466 events=r cmd=client user=default redir=-1
id=1578 addr=172.18.0.1:58860 laddr=172.18.0.2:6379 fd=8 name=hi age=19 idle=19 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 argv-mem=0 obl=0 oll=0 omem=0 tot-mem=20512 events=r cmd=client user=default redir=-1
id=1579 addr=172.18.0.1:58868 laddr=172.18.0.2:6379 fd=9 name=hi age=19 idle=19 flags=P db=0 sub=1 psub=0 multi=-1 qbuf=0 qbuf-free=0 argv-mem=0 obl=0 oll=0 omem=0 tot-mem=20504 events=r cmd=subscribe user=default redir=-1
id=1581 addr=172.18.0.1:58870 laddr=172.18.0.2:6379 fd=11 name=hi age=19 idle=19 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 argv-mem=0 obl=0 oll=0 omem=0 tot-mem=20512 events=r cmd=client user=default redir=-1

Application log

[ioredis] Unhandled error event: ReplyError: NOAUTH Authentication required.
    at parseError (/Users/fulvio/Developer/Work/app-mfa-backend/node_modules/redis-parser/lib/parser.js:179:12)
    at parseType (/Users/fulvio/Developer/Work/app-mfa-backend/node_modules/redis-parser/lib/parser.js:302:14)
luin commented 3 years ago

It's clear that the error logs came from other instances (aka you're creating redis instances in other places), and the code you posted works correctly (as the clients with the name of hi appear in the client list).

fulvi0 commented 3 years ago

Thank you for the orientation, found the issue in the code, as u said an orphan instance.

const Redis = require('ioredis');
const redisClient = new Redis({host: config.redis.redisHost, port: 6379});