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

Error: timeout reached while waiting for sockets response #371

Closed
cesco69 opened this issue Dec 10, 2020 · 6 comments
Closed

Error: timeout reached while waiting for sockets response #371

cesco69 opened this issue Dec 10, 2020 · 6 comments

Comments

@cesco69
Copy link

cesco69 commented Dec 10, 2020

{
    "socket.io": "^3.0.4",
    "socket.io-redis": "^6.0.1"
}

I'm try to retrive all socket with io.of(/namespace).in('room').allSockets():

import { RedisClient } from 'redis';
import { Server } from 'socket.io';
import { createAdapter } from 'socket.io-redis';

const redisClient = new RedisClient({ ... })
const io = new Server(httpServer, { path: '/api/socket.io' });
io.adapter(createAdapter({ pubClient: redisClient, subClient: redisClient.duplicate() }));
console.log( io.of(`/namespace`).in('room').allSockets() );

error

Error: timeout reached while waiting for sockets response
    at Timeout._onTimeout (...\node_modules\socket.io-redis\dist\index.js:286:28)
    at listOnTimeout (<node_internals>/internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

After a lot of debug there are some "ignoring unknown request" https://github.com/socketio/socket.io-redis/blob/4dae265a740129b0d86f16418319b902a0648a3c/lib/index.ts#L292 with the response object:

{
   "clients": []
}

I don't know if it is an expected behaviour...

However, when the right response.requestId reach onresponse the problem seem that, request.msgCount is never equal to request.numSub and the promise is never resolved.

https://github.com/socketio/socket.io-redis/blob/4dae265a740129b0d86f16418319b902a0648a3c/lib/index.ts#L309

the difference seem always:

{
   "msgCount": 1,
   "numSub": 5
}

I'm on dev machine (with a shared redis server for the team: 3 guys) and it seems a problem with getNumSub() https://github.com/socketio/socket.io-redis/blob/4dae265a740129b0d86f16418319b902a0648a3c/lib/index.ts#L614 that return wrong number of subscriber (maybe?).

Now, I don't understand the code but the the "pubsub" command seem returns the number of subscribers for the specified channels over the single instance, but request.msgCount is a counter into the single instance. How can those two numbers become equal?

Side note 1
Googling the error, there are others users with the same error:

Side note 2
However, it works with the old version.

@cesco69 cesco69 closed this as completed Dec 10, 2020
@cesco69
Copy link
Author

cesco69 commented Dec 10, 2020

fixed after a deep debug: is a my error.

The problem is: other guys into the dev team has opened another project that use the same redis but with a different version of socket.io-redis. The fix is add a unique key for each application into createAdapter:

io.adapter(createAdapter({ pubClient, subClient, key: 'uniquekey' }));

@daveteu
Copy link

daveteu commented Jul 20, 2021

I'm having the same error, and tried setting the key does work (for now). Though I am very curious.

  1. I've only recently used socket.io so the versions are the same
  2. Redis pub/sub are not like permanent channels. If you restart your redis server or restart your nodejs, all the connections will be closed isn't it? There shouldn't be a conflict causing this error...

@daveteu
Copy link

daveteu commented Jul 20, 2021

I just figured it out, it's not because of different versions of socket-io (for me).

I was using different db (select) for my production and development and I was assuming they are separate. Turn out and "db" are different things, and they end up using the same channel.

Now i use different key base on NODE_ENV

@andr333v
Copy link

andr333v commented Dec 9, 2022

I just figured it out, it's not because of different versions of socket-io (for me).

I was using different db (select) for my production and development and I was assuming they are separate. Turn out and "db" are different things, and they end up using the same channel.

Now i use different key base on NODE_ENV

@daveteu, Can you elaborate a bit? I am having the same issue and I am trying to understand the reason behind it. Thanks in advance!

@IEonid
Copy link

IEonid commented Jan 22, 2024

As for me, I just figured out that the reason of timeout error is because one of the subscriber node has lose its pubClient connection to the redis.

@santiarr
Copy link

santiarr commented Jun 1, 2024

fixed after a deep debug: is a my error.

The problem is: other guys into the dev team has opened another project that use the same redis but with a different version of socket.io-redis. The fix is add a unique key for each application into createAdapter:

io.adapter(createAdapter({ pubClient, subClient, key: 'uniquekey' }));

for me it was a similar issue except it was that both staging and local dev servers were using the same redis connection so to fix it I did this:

const key = APP_NAME + process.env.NODE_ENV;

server.io.adapter(createAdapter(redis, subscriber, { key }));

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

No branches or pull requests

5 participants