Memory leak when sharding

I'm experiencing a memory leak when using sharding in my bot, obviously memory leaks are hard to debug so I just would like some advice on how to diagnose the issue. The bot slowly rises in memory usage up to 2-3 gbs until it runs out of memory. I tried running heap snapshots, but that didn't provide meaningful results. I've tried using discord-hybrid-sharding and without it, with the same results. I've tried switching tokens to a bot with around 5 servers, and memory usage started low due to having less things to cache, but always grew in memory until crashing. Yet, removing the sharding refactor never had memory climb indefinitely. Has anyone experienced similar issues, I'd appreciate some advice on what to do/where to look.
4 Replies
d.js toolkit
d.js toolkit3d ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
logic
logicOP3d ago
Cluster.ts
import { ShardingManager } from "discord.js";
import config from "./models/Config";

const manager = new ShardingManager(`${__dirname}/bot.js`, {
token: config.token,
totalShards: "auto"
});

manager.on('shardCreate', shard => {
console.log(`[SHARD ${shard.id}]: Launched`);
shard.on("ready", async () => {
console.log(`[SHARD ${shard.id}]: Ready`);
});
});

manager.spawn({ timeout: -1 })
.catch(console.error);
import { ShardingManager } from "discord.js";
import config from "./models/Config";

const manager = new ShardingManager(`${__dirname}/bot.js`, {
token: config.token,
totalShards: "auto"
});

manager.on('shardCreate', shard => {
console.log(`[SHARD ${shard.id}]: Launched`);
shard.on("ready", async () => {
console.log(`[SHARD ${shard.id}]: Ready`);
});
});

manager.spawn({ timeout: -1 })
.catch(console.error);
Lmk what other files i should send dev bot without sharding = ~150 mb dev bot with sharding = 490 mb at start and climbs rapidly without stabilizing prod bot without sharding = (cant because its above 2500) prod bot with sharding = 2000 mb at start and climbs without stabilizing
🗿Patryk🍷
I also have this problem. After starting the bot with sharding about 85mb and after about 2 days 120mb But after just 3 days 180mb
Erick
Erick3d ago
is there a way to clear them?
Want results from more Discord servers?
Add your server