status-sharding cluster died

Hello, so my bot is up and running fine but every now an then I get this in my console and I have to restart my bot.. LOG [SYSTEM] [ClusterID: 0] died This is my code:
const manager = new ClusterManager(path.join(__dirname, 'bot.js'), {
mode: 'process',
token: process.env.token,
totalShards: 2,
totalClusters: 1
});


manager.on('clusterCreate', (cluster) => {
['unhandledRejection', 'uncaughtException', 'uncaughtExceptionMonitor'].forEach((event) => {
process.on(event, logger.log);
});

logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] Launched`);

cluster.on('ready', () => logger.ready(`[SYSTEM] [ClusterID: ${cluster.id}] is ready`));

cluster.on('death', () => logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] died`));

cluster.on('error', () => logger.error(`[SYSTEM] [ClusterID: ${cluster.id}] errored`));

cluster.on('spawn', () => logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] has spawned`));
});

manager.spawn();
const manager = new ClusterManager(path.join(__dirname, 'bot.js'), {
mode: 'process',
token: process.env.token,
totalShards: 2,
totalClusters: 1
});


manager.on('clusterCreate', (cluster) => {
['unhandledRejection', 'uncaughtException', 'uncaughtExceptionMonitor'].forEach((event) => {
process.on(event, logger.log);
});

logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] Launched`);

cluster.on('ready', () => logger.ready(`[SYSTEM] [ClusterID: ${cluster.id}] is ready`));

cluster.on('death', () => logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] died`));

cluster.on('error', () => logger.error(`[SYSTEM] [ClusterID: ${cluster.id}] errored`));

cluster.on('spawn', () => logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] has spawned`));
});

manager.spawn();
How can I prevent it / is it possible to "revive" the dead cluster on cluster death?
26 Replies
Digital
Digital14mo ago
1. your code somehow crashes the cluster by exiting the process 2. to add logs for that, you can setup this (image below) in your main and cluster files, so it tells you the issue instead of dying 3. yes, you can use heartbeat system, by passing in heartbeat: { enabled: true } in manager options
No description
notvexi
notvexiOP14mo ago
Cant I do something like this? or will this not work:
cluster.on('death', () => {
logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] died`);

logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] Attempting to respawn...`);
cluster.respawn().then(() => {
logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] Successfully respawned`);
}).catch((error) => {
logger.error(`[SYSTEM] [ClusterID: ${cluster.id}] Failed to respawn: ${error}`);
});
});
cluster.on('death', () => {
logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] died`);

logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] Attempting to respawn...`);
cluster.respawn().then(() => {
logger.log(`[SYSTEM] [ClusterID: ${cluster.id}] Successfully respawned`);
}).catch((error) => {
logger.error(`[SYSTEM] [ClusterID: ${cluster.id}] Failed to respawn: ${error}`);
});
});
Digital
Digital14mo ago
you can, instead of 3rd note, but i still suggest you to prevent crashing of clusters as said in 2nd note
notvexi
notvexiOP14mo ago
well the thing is I had the thing you mentioned in step 2 already implemented and no error was showing. I just saw random in my console today LOG [SYSTEM] [ClusterID: 0] died
No description
Digital
Digital14mo ago
well that will prevent it dying next time it wants to
notvexi
notvexiOP14mo ago
so what would you do. would wou still implement process.on("warning")?
Digital
Digital14mo ago
well i screenshoted my code above, so, it doesnt hurt to have
notvexi
notvexiOP14mo ago
wait you said in your "main and cluster" files.? I only have this (image) in my main file. I start from index.js (where the image is) and there it calls bot.js the actual bot file
Digital
Digital14mo ago
your bot.js file crashes, just put those 3 in both files, like at the bottom or at the top
notvexi
notvexiOP14mo ago
ok ill try that but in any case this will work right?
Digital
Digital14mo ago
yes, but difference between that and those 3 lines from my ss is that my 3 lines will prevent death from even happening
notvexi
notvexiOP14mo ago
tru wait I am dumb tho i have those as well?
notvexi
notvexiOP14mo ago
No description
Digital
Digital14mo ago
put them fully outside of any function, and copy them over to bot.js file too
notvexi
notvexiOP14mo ago
okay ty so with these startup files: index.js: https://sourceb.in/zxi1sRWmfG bot.js: https://sourceb.in/wMxyNcdZEW the bot just crashed after 2d, 14h. This is what I seein the console:
notvexi
notvexiOP14mo ago
No description
Digital
Digital14mo ago
hm weird that error is when sharding couldnt find the process to terminate on restart
notvexi
notvexiOP14mo ago
any suggestions on what I could do to fix it?
Digital
Digital14mo ago
im not sure, i run the same much bigger codebases on it and i never had such issues what's your Client
notvexi
notvexiOP14mo ago
its a custom class from which extends status-sharding https://sourceb.in/pYEitfiILS
Digital
Digital14mo ago
my only guess would be that you tripple check that you dont somewhere import a file that is used by manager into client or vice versa, ei: - this below will fail, or if you import Lunio client in some file that manager uses client.js:
const test = require('../functions');
const test = require('../functions');
functions.js:
const CustomManager = require('status-sharding')
const CustomManager = require('status-sharding')
manager:
const test = require('../functions');
const test = require('../functions');
notvexi
notvexiOP14mo ago
okay thanks ill check for that then
notvexi
notvexiOP13mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
notvexi
notvexiOP13mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Digital
Digital13mo ago
yes if course, we dont interfere with discord.js new ShardingClient({ .... })
notvexi
notvexiOP13mo ago
okay thanks

Did you find this page helpful?