Skip to content

TypeError: Cannot destructure property 'master' of 'this.slots[calculateSlot(...)]' as it is undefined #546

@noor-siddique-paypay

Description

@noor-siddique-paypay

I'm encountering an unexpected error when utilizing the socket.io/redis-adapter in my application. Below are the error logs for your reference:

Environment:

Node.js Version: v20.9.0
Redis Instance Version: AWS ElastiCache 7.0.7

Dependencies:

"redis": "4.7.0"
"@socket.io/redis-adapter": "^8.3.0"
"socket.io": "4.7.5"

Code sample:

const pubClient = RedisClient.createCluster({
        rootNodes: [
          {
            socket: {
              host: ".....cache.amazonaws.com",
              port: "6379"
            }
          },
        ],
        defaults: {
          username: "username",
          password: "password",
          socket: {
            tls: true,
            rejectUnauthorized: false
          }
        }
      });

const subClient = pubClient.duplicate();

(async () => {
  await Promise.all([
    pubClient.connect(),
    subClient.connect()
  ]);
})();

io.adapter(createShardedAdapter(pubClient, subClient)); // failing at this stage

Error Log:

/app/node_modules/@redis/client/dist/lib/cluster/cluster-slots.js:144
        const { master } = this.slots[calculateSlot(channel)];
                ^

TypeError: Cannot destructure property 'master' of 'this.slots[calculateSlot(...)]' as it is undefined.
    at RedisClusterSlots.getShardedPubSubClient (/app/node_modules/@redis/client/dist/lib/cluster/cluster-slots.js:144:17)
    at Commander.SSUBSCRIBE (/app/node_modules/@redis/client/dist/lib/cluster/index.js:166:83)
    at SSUBSCRIBE (/app/node_modules/@socket.io/redis-adapter/dist/util.js:54:21)
    at new ShardedRedisAdapter (/app/node_modules/@socket.io/redis-adapter/dist/sharded-adapter.js:39:31)
    at new <anonymous> (/app/node_modules/@socket.io/redis-adapter/dist/sharded-adapter.js:23:16)
    at Namespace._initAdapter (/app/node_modules/socket.io/dist/namespace.js:93:24)
    at Server.adapter (/app/node_modules/socket.io/dist/index.js:188:17)
    at Object.startIo (/app/socket.io/index.js:224:6)
    at Object.<anonymous> (/app/bin/www:57:27)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions