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