Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnection causes the program to crash when receiving a message from a channel #2876

Open
ignorantshr opened this issue Dec 4, 2024 · 1 comment
Labels

Comments

@ignorantshr
Copy link

Description

Steps to Reproduction

  1. Create a Redis client and subscribe to a channel
  2. Connection timeout occurs when connecting to the server
  3. Wait for client to reconnect to the server
  4. Publish a message
  5. 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)
@ignorantshr ignorantshr added the Bug label Dec 4, 2024
@ignorantshr
Copy link
Author

this may be a cause of issues #2417 and #2626

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

No branches or pull requests

1 participant