redis / ioredis

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

Command queue state error: `parsing "NaN": invalid syntax` #1920

Open steamwings opened 1 month ago

steamwings commented 1 month ago

Running into this trying to deploy a Mastodon server.

The error

Redis Client Error! Error: Command queue state error. If you can reproduce this, please report it. Last reply: OK
    at DataHandler.shiftCommand (/opt/mastodon/node_modules/ioredis/built/DataHandler.js:173:27)
    at DataHandler.returnReply (/opt/mastodon/node_modules/ioredis/built/DataHandler.js:50:27)
    at JavascriptRedisParser.returnReply (/opt/mastodon/node_modules/ioredis/built/DataHandler.js:21:22)
    at JavascriptRedisParser.execute (/opt/mastodon/node_modules/redis-parser/lib/parser.js:544:14)
    at Socket.<anonymous> (/opt/mastodon/node_modules/ioredis/built/DataHandler.js:25:20)
    at Socket.emit (node:events:514:28)
    at Socket.emit (node:domain:552:15)
    at addChunk (node:internal/streams/readable:343:12)
    at readableAddChunk (node:internal/streams/readable:316:9)
    at Readable.push (node:internal/streams/readable:253:10)
Uncaught ReplyError: strconv.Atoi: parsing "NaN": invalid syntax
    at parseError (/opt/mastodon/node_modules/redis-parser/lib/parser.js:179:12)
    at parseType (/opt/mastodon/node_modules/redis-parser/lib/parser.js:302:14) {
  command: { name: 'select', args: [ 'NaN' ] }

Seems like it may be an issue with redis-parser? Please let me know if other context would be useful.

EDIT: After setting showFriendlyErrorStack: true, the last bit looks different:

Uncaught ReplyError: strconv.Atoi: parsing "NaN": invalid syntax
    at tryCatcher (/opt/mastodon/node_modules/standard-as-callback/built/utils.js:12:23)
    at /opt/mastodon/node_modules/standard-as-callback/built/index.js:22:53
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  command: { name: 'select', args: [ 'NaN' ] }

EDIT 2:

Here's a snippet of the code context. You can see the source here. I think the only important context here is that nothing has been done with the Redis instance except to create it.

  const createRedisClient = async (config) => {
    const { redisParams, redisUrl } = config;
    const client = new Redis(redisUrl, redisParams);
    client.on('error', (err) => log.error('Redis Client Error!', err));
    return client;
  };
  ...
  const redisSubscribeClient = await createRedisClient(redisConfig);

EDIT 3: This looks suspicious

EDIT 4: Here's the additional output from starting node with DEBUG=ioredis:*

ioredis:redis status[<ip>]: connecting -> connect +27ms
  ioredis:redis write command[<ip>]: NaN -> auth([ 'default', '<oopshadtoresetthispassword>' ]) +1ms
  ioredis:redis write command[<ip>]: NaN -> info([]) +3ms
  ioredis:redis status[<ip>]: connect -> ready +14ms
  ioredis:connection connect to db [NaN] +0ms
  ioredis:redis write command[<ip>]: NaN -> select([ 'NaN' ]) +0ms
steamwings commented 1 month ago

Looks like my issue was caused by passing db: 'default' in the config. The issue resolved when I passed 0 for db instead.

Still, this should probably be fixed, so I'll leave this open.