Open
Description
Description
Steps to Reproduction
- Create a Redis client and subscribe to a channel
- Connection timeout occurs when connecting to the server
- Wait for client to reconnect to the server
- Publish a message
- Program crashes when receiving message
Code
options = {socket: {host: cacheOptions.host, port: cacheOptions.port}}
acacheOperators = redis.createClient(options)
acacheOperators.connect()
# another client
bcacheOperators.SUBSCRIBE(...)
Solution
I found that when a timeout occurs, node-redis will reset the state of the subscribed client. After reconnecting, the client is no longer subscribed!
This happens in the reset()
method of node_modules/@redis/client/dist/lib/client/pub-sub.js
.
While I can temporarily fix this by prolonging the connectTimeout, I think it would be better to fix it in the code itself.
Node.js Version
v20.13.1
Redis Server Version
6.0.15
Node Redis Version
4.7.0
Platform
linux
Logs
TypeError: Cannot destructure property 'resolve' of '__classPrivateFieldGet(...).shift(...)' as it is undefined.
at Object.onReply (/node_modules/@redis/client/dist/lib/client/commands-queue.js:64:25)
at RESP2Decoder.write (/node_modules/@redis/client/dist/lib/client/RESP2/decoder.js:119:26)
at RedisCommandsQueue.onReplyChunk (/node_modules/@redis/client/dist/lib/client/commands-queue.js:156:72)
at RedisSocket.<anonymous> (/node_modules/@redis/client/dist/lib/client/index.js:420:84)
at RedisSocket.emit (node:events:519:28)
at RedisSocket.emit (node:domain:488:12)
at Socket.<anonymous> (/node_modules/@redis/client/dist/lib/client/socket.js:201:42)
at Socket.emit (node:events:519:28)
at Socket.emit (node:domain:488:12)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Socket.Readable.push (node:internal/streams/readable:390:5)
at TCP.onStreamRead (node:internal/stream_base_commons:191:23)
Activity