jack3898 / discord-youtube-bot-2

A powerful Discord YouTube Bot.
0 stars 0 forks source link

ConnectionTimeoutError from globals.redisClient.connect() #12

Closed DheathNone closed 2 years ago

DheathNone commented 2 years ago

I'm always getting time out error for Redis after the move of globals.redisClient.connect(); from src/config/modules/globals.ts to src/events/modules/ready.ts. When I move the globals.redisClient.connect(); back it works.

...
bot      | Started refreshing application slash commands.
bot      | 19 unique commands have been found on the file system.
bot      | /home/node/node_modules/@node-redis/client/dist/lib/client/socket.js:163
bot      |             socket.setTimeout(__classPrivateFieldGet(this, _RedisSocket_options, "f").connectTimeout, () => socket.destroy(new errors_1.ConnectionTimeoutError()));
bot      |                                                                                                                            ^
bot      | ConnectionTimeoutError: Connection timeout
bot      |     at Socket.<anonymous> (/home/node/node_modules/@node-redis/client/dist/lib/client/socket.js:163:124)
bot      |     at Object.onceWrapper (node:events:639:28)
bot      |     at Socket.emit (node:events:520:28)
bot      |     at Socket.emit (node:domain:475:12)
bot      |     at Socket._onTimeout (node:net:501:8)
bot      |     at listOnTimeout (node:internal/timers:559:17)
bot      |     at processTimers (node:internal/timers:502:7)
bot exited with code 1

I'm not sure but I think this might be because of I'm running this on quite a slow system. When looking into this I noticed this:

https://github.com/redis/node-redis/issues/1656

We had this issue on our project. The root cause is that we try to .connect(), and then require many node modules blocking the node loop with sync calls. The socket is blocked and the timeout is thrown. I suggest you to profile your applications to find if it's the same kind of error.

DheathNone commented 2 years ago

I can try to debug this more if there are any ideas to try.

jack3898 commented 2 years ago

Can you perform a search on your project and identify if there is only one instance of redisClient.connect()? 🤔

Jack

DheathNone commented 2 years ago

This is the only one instance. There are not really modifications to the upstream aside from some minor docker configurations to make it run on Raspberry pi.

jack3898 commented 2 years ago

You say you moved the connect() method call from globals.ts to ready.ts and that allows it to work. This is, however, the default configuration. Could you clarify this?

DheathNone commented 2 years ago

The other way around. This issue started to occur after commit: cd601b43316d03882986628b2e82e802523f2303

By reverting the connect() to globals.ts the issue goes away.

LunarstarPony commented 2 years ago

I'm also having the same issue rn and help on fixing it? Whatcha mean by reverting connect() to globals.ts? or is there like a complete file I can just copy and paste?

jack3898 commented 2 years ago

Hi guys this should be fixed in the latest commit! @DheathNone fix makes sense, because the redis client would ONLY connect when the bot has logged in whereas in the globals file it tries to connect to Redis straight away. Simple oversight on my part. 😁

Jack