node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

Got an unexpected reply from Redis on unsubscribing from multiple channels at once

Open mifopen opened this issue 3 years ago • 3 comments

I have a very simple script:

const sub = createClient();
function handler(...args) {
    console.log(...args);
}
await sub.subscribe(['some1', 'some2'], handler);
setTimeout(() => {
    sub.unsubscribe(['some1', 'some2'], handler);
}, 5000);

And after 5sec it crashes with the following stacktrace:

/Users/mif/Documents/GitHub/uify/apps/frontend/src/node_modules/@node-redis/client/dist/lib/client/commands-queue.js:285
        throw new Error('Got an unexpected reply from Redis');
              ^
Error: Got an unexpected reply from Redis
    at RedisCommandsQueue._RedisCommandsQueue_shiftWaitingForReply (/Users/mif/Documents/GitHub/uify/apps/frontend/src/node_modules/@node-redis/client/dist/lib/client/commands-queue.js:285:15)
    at JavascriptRedisParser.returnReply (/Users/mif/Documents/GitHub/uify/apps/frontend/src/node_modules/@node-redis/client/dist/lib/client/commands-queue.js:58:124)
    at JavascriptRedisParser.execute (/Users/mif/Documents/GitHub/uify/apps/frontend/src/node_modules/redis-parser/lib/parser.js:544:14)
    at RedisCommandsQueue.parseResponse (/Users/mif/Documents/GitHub/uify/apps/frontend/src/node_modules/@node-redis/client/dist/lib/client/commands-queue.js:194:71)
    at RedisSocket.<anonymous> (/Users/mif/Documents/GitHub/uify/apps/frontend/src/node_modules/@node-redis/client/dist/lib/client/index.js:336:83)
    at RedisSocket.emit (node:events:527:28)
    at RedisSocket.emit (node:domain:475:12)
    at Socket.<anonymous> (/Users/mif/Documents/GitHub/uify/apps/frontend/src/node_modules/@node-redis/client/dist/lib/client/socket.js:189:44)
    at Socket.emit (node:events:527:28)
    at Socket.emit (node:domain:475:12)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Socket.Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

Environment:

  • Node.js Version: 17.6.0
  • Redis Server Version: Redis server v=6.2.6 sha=00000000:0 malloc=libc bits=64 build=f91e6fead97295d3
  • Node Redis Version: 4.0.4
  • Platform: Mac OS 12.2.1 (21D62)

mifopen avatar Mar 23 '22 19:03 mifopen

And one more question — how to gracefully handle such an exception? I've tried sub.on('error',... but unsuccessfully.

mifopen avatar Mar 23 '22 19:03 mifopen

Redis's MONITOR is showing "UNSUBSCRIBE" "some1" "some2"

mifopen avatar Mar 23 '22 19:03 mifopen

@mifopen how are you getting MONITOR to work?

joeyparis avatar Mar 29 '22 15:03 joeyparis

@mifopen Did you get any solution for this?

I'm facing same issue.

omkarrepal avatar Nov 16 '22 19:11 omkarrepal

Unfortunately, no :(

mifopen avatar Nov 16 '22 20:11 mifopen

@omkarrepal @mifopen I just tried to reproduce the error using this script

import { createClient } from '@redis/client';

const sub = createClient();
await sub.connect();

function handler(...args) {
    console.log(...args);
}
await sub.subscribe(['some1', 'some2'], handler);
setTimeout(async () => {
  await sub.unsubscribe(['some1', 'some2'], handler);
  await sub.disconnect();
}, 5000);

but it works as expected. have you tried upgrading to the latest node-redis version?

leibale avatar Nov 16 '22 21:11 leibale