discord.js icon indicating copy to clipboard operation
discord.js copied to clipboard

SHARDING_READY_TIMEOUT Shard 0's Client took too long to become ready.

Open pab14567 opened this issue 3 years ago • 14 comments

Issue description

My bot is currently at 11 shards for it, and when I try to start the bot on my VPS which has 4vCores and 4GB of ram, one shard out of the 11 randomly takes too long to respond, and it causes every other shard to stop launching. This is happening every time now when I try to start the bot, however when I run the bot on my own Machine with 32GB of ram, and an i7 9700k, the bot works perfectly fine and all 11 shards launch perfectly fine.

I've tried it on 2 seperate VPS's, with the same ram and cores, different operating systems and still the same issue. The owners of the hosting company have also increased the ram of the VPS to 32GB just like my main PC, and still same issue of SHARDING READY TIMEOUT.

Does anyone have any ideas for this as to what could be causing it, and why this only happens on the VPS's, and not on my own machine?

Below is my sharding file.

I've tried multiple solutions that I could find anywhere, including on this github for Discord.js

Including https://github.com/discordjs/discord.js/issues/2323

and https://github.com/discordjs/discord.js/issues/3956 but to no conclusion or solution.

I have marked this as medium attention just due to this has been going on for the last several weeks as the bot gets bigger and bigger, and I have been unable to come to any solution in regards to this issue and my bot is now currently being forced to stay offline since now it won't go past Shard 2 taking too long to be ready.

Code sample

const { ShardingManager } = require('discord.js');
const { token, dblToken } = require('./cfg.json');
const manager = new ShardingManager('./bot.js', {
  token,
  totalShards: 11,
  respawn: true,
  spawnTimeout = -1
});
const { AutoPoster } = require('topgg-autoposter')
 const ap = AutoPoster(dblToken, manager)

manager.on("shardCreate", shard => {
  shard.on('reconnecting', () => {
    console.log(`Reconnecting shard: [${shard.id}]`);
  });
  shard.on('spawn', () => {
    console.log(`Spawned shard: [${shard.id}]`);
  });
  shard.on('ready', () => {
    console.log(` Shard [${shard.id}] is ready`);
  });
  shard.on('death', () => {
    console.log(`Died shard: [${shard.id}]`);
  });
  shard.on('error', (err)=>{
    console.log(`Error in  [${shard.id}] with : ${err} `)
    shard.respawn()
  })
});

 ap.on('posted', () => {
  console.log('Posted Stats.')
}) 

manager.spawn();

discord.js version

13.4.0

Node.js version

v17.3.0

Operating system

Was tested on Linux and Windows.

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS

I have tested this issue on a development release

No response

pab14567 avatar Jan 07 '22 02:01 pab14567

I have the same issue on my Linux VPS. I can't get past shard 0 now. I start it in nodemon, launches the shard. Bot connects to channel and immediately timesout but creates another instance of the bot. Luckily for me, I can use CTRL + C to close out the task and shut down both instances of the bot.

Peter-MJ-Parker avatar Jan 27 '22 15:01 Peter-MJ-Parker

So I’d like to take a point on this. When looking at the code it seems Discord.js uses Promise.all when spawning shards. which if one of the process were to error the rest won’t be executed hence when you get the error the rest of shards aren’t spawned or do nothing.

Drxckzyz avatar Feb 19 '22 15:02 Drxckzyz

Should not be stale.. This issue still valid.

fzn0x avatar Apr 22 '22 14:04 fzn0x

So I’d like to take a point on this. When looking at the code it seems Discord.js uses Promise.all when spawning shards. which if one of the process were to error the rest won’t be executed hence when you get the error the rest of shards aren’t spawned or do nothing.

That’s not true, just because the Promise.all will reject on the rejection of one of the promises doesn’t magically stop the other asynchronous functions from running. It’s just that their resolution/rejection won’t matter for the Promise.all anymore. But the other shards will keep on connecting.

Qjuh avatar May 22 '22 18:05 Qjuh

Has anyone find a fix to this issue? Thank you

positivesquare avatar Jun 14 '22 21:06 positivesquare

Hello same issue, I've tried to restart it several times already. Even with a change of token to cut it, always the same problem.

 Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
12||     at Timeout.onTimeout (*/node_modules/discord.js/src/sharding/Shard.js:166:16)
12||     at listOnTimeout (node:internal/timers:557:17)
12||     at processTimers (node:internal/timers:500:7) {
12||   [Symbol(code)]: 'SHARDING_READY_TIMEOUT'
12|| }

Version discord.js : 13.6.0 Version Node.js : 17.0.1

thomasbnt avatar Jul 02 '22 21:07 thomasbnt

Having the same issue

npm ls discord.js └── [email protected] node --version v16.3.0

knobse avatar Jul 08 '22 14:07 knobse

Same problem.

megahypercat avatar Jul 22 '22 18:07 megahypercat

I'm also having the same issue. Need help ASAP

aelxxs avatar Jul 23 '22 16:07 aelxxs

Hello @aelxxs, for my part I edited my code, and he works :

const shard = new ShardingManager("./core.js", {
    totalShards: "auto",
    token: config.token,
    timeout: -1,
    respawn: true
})

shard.on('shardCreate', shard => {
    console.log(`Shard ID #${shard.id}`)
})

shard.spawn({ amount: 'auto', delay: 5500, timeout: 30000 }).catch(e => console.log(e))

thomasbnt avatar Jul 23 '22 16:07 thomasbnt

Hello @aelxxs, for my part I edited my code, and he works :

const shard = new ShardingManager("./core.js", {
    totalShards: "auto",
    token: config.token,
    timeout: -1,
    respawn: true
})

shard.on('shardCreate', shard => {
    console.log(`Shard ID #${shard.id}`)
})

shard.spawn({ amount: 'auto', delay: 5500, timeout: 30000 }).catch(e => console.log(e))

Thanks! I ended up having to update to a newer (supported) version of Discord.JS. My bot was really outdated.

It works great now. Don't know what the cause of the error is though.

aelxxs avatar Jul 23 '22 20:07 aelxxs

also having this issue on latest version

shrimpsicle avatar Aug 07 '22 05:08 shrimpsicle

Thanks! I ended up having to update to a newer (supported) version of Discord.JS. My bot was really outdated.

It works great now. Don't know what the cause of the error is though.

@aelxxs Hmmm I got the error again with these settings... 😡

Edited the shard.spawn conf with

shard.spawn({ amount: 'auto', delay: 15500, timeout: 60000 }).catch(e => console.log(e))

Seems better 🤔

thomasbnt avatar Aug 09 '22 01:08 thomasbnt

Thanks! I ended up having to update to a newer (supported) version of Discord.JS. My bot was really outdated. It works great now. Don't know what the cause of the error is though.

@aelxxs Hmmm I got the error again with these settings... 😡

Edited the shard.spawn conf with

shard.spawn({ amount: 'auto', delay: 15500, timeout: 60000 }).catch(e => console.log(e))

Seems better 🤔

Nice, I don't really know what caused the issue. I'm moving away from Discord.JS though so I won't be bothering with finding a solution

aelxxs avatar Aug 09 '22 01:08 aelxxs