socket.io-redis-adapter icon indicating copy to clipboard operation
socket.io-redis-adapter copied to clipboard

Error: timeout reached while waiting for sockets response

Open hamitsaka opened this issue 3 years ago • 15 comments

[email protected] [email protected]

Calls made to the adapter methods as follows: ` const sockets = await io.of('/').adapter.sockets(); console.log(sockets); // a Set containing all the connected socket ids

// 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' `

Causes the below exception being thrown: (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)

hamitsaka avatar Dec 02 '20 00:12 hamitsaka

same error

cesco69 avatar Dec 10 '20 09:12 cesco69

Getting this error. Any clue for fixes?

alkalox avatar Mar 11 '22 18:03 alkalox

I am having the same issue and I'm at a loss on how to stop it.

Error: timeout reached while waiting for sockets response at Timeout._onTimeout (/app/node_modules/@socket.io/redis-adapter/dist/index.js

This is with: "socket.io": "^4.4.0" "@socket.io/redis-adapter": "^7.0.1"

I've pretty much wrapped everything in try/catch blocks and .catch() where promises are involved. Really need a solution here.

unicornsoftwareinc avatar May 09 '22 18:05 unicornsoftwareinc

getting this error randomly

andreuka avatar Jul 28 '22 22:07 andreuka

Same error using ioredis

lehno avatar Aug 04 '22 11:08 lehno

This happened to me when the connection of the socket server loses connection to the redis server. We had it happen when our redis server went down and we tried to send things via redis

willjk avatar Dec 14 '22 19:12 willjk

Happening to me too.

Using ioredis for connection and fetchSockets instead of allSockets due to the deprecation of allSockets sice [email protected], but the result is the same.

Error: timeout reached while waiting for fetchSockets response
    at Timeout._onTimeout (/node_modules/@socket.io/redis-adapter/dist/index.js:559:28)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7)

gabrielgrijincu avatar May 09 '23 13:05 gabrielgrijincu

Same problem when the number of clients is large.

hysapp avatar Sep 01 '23 17:09 hysapp

Same error here. Looking at the lib seems like the error is generated on this line: https://github.com/socketio/socket.io-redis-adapter/blob/ef5f0da0b4928fd422afc985aec0e233d34400c0/lib/index.ts#L759

@darrachequesne Can you help us? What is the logic of this if that generates the error?

    if (this.requests.has(requestId)) {
      reject(
        new Error("timeout reached while waiting for fetchSockets response")
      );
      this.requests.delete(requestId);
    }

italosvieira avatar Sep 20 '23 21:09 italosvieira

I am seeing this issue as well intermittently

cody-evaluate avatar Oct 28 '23 02:10 cody-evaluate

seems to happen when numSub and msgCount are off by 1

{ type: 5, numSub: 3, resolve: [Function (anonymous)], timeout: Timeout { _idleTimeout: 5000, _idlePrev: [TimersList], _idleNext: [Timeout], _idleStart: 5650, _onTimeout: [Function (anonymous)], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: true, [Symbol(kHasPrimitive)]: false, [Symbol(asyncId)]: 391, [Symbol(triggerId)]: 0 }, msgCount: 2, sockets: [] }

cody-evaluate avatar Oct 28 '23 02:10 cody-evaluate

me too

introspection3 avatar Nov 05 '23 11:11 introspection3

allSockets

allSockets works for me, my app deployed on k8, on single instance it was fine, fetchsocket timeout on multiple instances

alirafiq-js avatar Nov 10 '23 17:11 alirafiq-js

anyone found a solution??

HannaSamia avatar Jan 18 '24 10:01 HannaSamia

The timeout might happen if the requesting server does not receive enough responses from the other servers in the cluster.

Catching the exception and retrying upon failure should account for those temporary issues:

async function fetchSockets() {
  for (let i = 0; i < MAX_RETRIES; i++) {
    try {
      return await io.in("room1").fetchSockets();
    } catch (e) {
      // timeout error
    }
  }
  throw "too many retries";
}

darrachequesne avatar Jan 22 '24 07:01 darrachequesne