1

I have recently upgraded from Socket.io 2.x to 3.0.3 and use it with socket-io-redis@6.0.1.

As per explained in the original migration docs, I'm trying to get a list of all the open sockets with:

const ids = await io.allSockets();

This results in the below error:

(node:20818) UnhandledPromiseRejectionWarning: Error: timeout reached while waiting for sockets response
    at Timeout._onTimeout (/var/app/node_modules/socket.io-redis/dist/index.js:286:28)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)
(node:20818) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

Please note that there are only a few clients connected to my dev environment, so it is trying to deal with too much data that could really result in timing out.

I get the same error when I try running below:

const sockets = await io.of('/').adapter.sockets();
console.log(sockets); // a Set containing all the connected socket ids

const sockets = await io.of('/').adapter.sockets(new Set(['room1', 'room2']));
console.log(sockets); // a Set containing the socket ids in 'room1' or in 'room2'

// this method is also exposed by the Server instance
const sockets = io.in('room3').allSockets();
console.log(sockets); // a Set containing the socket ids in 'room3'

If anyone has any idea about what's causing the issue and how to fix it, it would be much appreciated.

Best

H

hmt
  • 69
  • 7

1 Answers1

1

There was another socket.io server with a previous version (v2.x) running on the same server and connected to the same Redis server and that was what caused the issue.

Stopping the other socket.io servers with v2.x and flushing the redis database have fixed the issue.

hmt
  • 69
  • 7
  • the same issue i faced still now but i run only one socket.io in my server. – Annamalai Feb 07 '22 at 06:26
  • I spent a day with an issue with my adapter, because of your comment here, I figured I had 2 servers locally pointing to the same Redis. Thank you for explaining it here – Leandro Hoffmann Aug 04 '22 at 13:26