meister03 / discord-cross-hosting

The ultimate package, which allows broadcastEvaling over Machines and effecient Shard Managing
MIT License
56 stars 14 forks source link

Failed to send, connection not available #20

Closed DakshNamdev closed 6 months ago

DakshNamdev commented 1 year ago

Whever i start cluster after bridge starts up, the cluster says it's connected to bridge but then errors up.

I've hopefully sent the required things for you to debug.

Bridge's Output

[Bridge] [READY] Bridge operational on :::1162
Server is ready :::1162
[Bridge] Created shardClusterList: [[[0],[1]]]
[Bridge => CM] [SHARDLIST_DATA_UPDATE][0] To all connected Clients

Cluster's Output

[CROSS-DEBUG] [CM] [Connect] Connecting to Bridge with the given Data
[CROSS-DEBUG] [CM] [Ready] Client connected to Bridge
[CROSS-ERROR] Error: Failed to send, connection not available
    at BridgeClient._tryWrite ([REDACTED]/node_modules\net-ipc\src\client.js:251:28)
    at BridgeClient._tryWrite ([REDACTED]/node_modules\net-ipc\src\client.js:260:17)

Bridge.js

import * as dotenv from 'dotenv';
dotenv.config({ path: "../.env" });

import { Bridge } from 'discord-cross-hosting';

const server = new Bridge({
    port: 1162,
    authToken: Buffer.from(process.env.TOKEN),
    totalShards: 2, // The Total Shards of the Bot or 'auto'
    totalMachines: 1, // The Total Machines, where the Clusters will run
    shardsPerCluster: 1, // The amount of Internal Shards, which are in one Cluster
    token: process.env.TOKEN,
});

server.on('debug', console.log);
server.start();
server.on('ready', url => {
    console.log('Server is ready', url);
    /**setInterval(() => {
        server.broadcastEval('this.guilds.cache.size').then(console.log).catch(console.log);
    }, 10000); */
});

Cluster.js

import * as dotenv from 'dotenv';
dotenv.config({ path: "../.env" });

import CrossHosting from "discord-cross-hosting";
import { ClusterManager } from "discord-hybrid-sharding";

const client = new CrossHosting.Client({
    agent: 'bot', host: '127.0.0.1',
    port: 1162, authToken: process.env.TOKEN,
    rollingRestarts: false,
})

client.on('debug', (data) => console.log(`[CROSS-DEBUG] ${data}`));
client.connect();

const manager = new ClusterManager('src/index.js', {
    token: process.env.TOKEN,
    mode: 'process',
    totalShards: 'auto',
    shardsPerClusters: 1
});

manager.on('clusterCreate', cluster => console.log(`[CLUSTER] Launched Cluster ${cluster.id}`));
manager.on('debug', (data) => console.log(`[CLUSTER-DEBUG] ${data}`));

client.listen(manager);
client.requestShardData().then((e) => {
    if (!e || !e.shardList) return;
    manager.totalShards = e.totalShards;
    manager.totalClusters = e.shardList.length;
    manager.shardList = e.shardList;
    manager.clusterList = e.clusterList;
    manager.spawn({ timeout: -1 });
}).catch(e => console.log(`[CROSS-ERROR]`, e));

in Bot file or src/index.js

Discord.Client's options are set to

    shards: getInfo().SHARD_LIST,
    shardCount: getInfo().TOTAL_SHARDS

and below

import { ClusterClient, getInfo } from 'discord-hybrid-sharding';
import CrossHosting from "discord-cross-hosting";
client.cluster = new ClusterClient(manager);
client.shard = new CrossHosting.Shard(manager.cluster);
Youzi9601 commented 1 year ago

I've also experienced this issue. (@~@ But is error in dashboard.

Code:

const { Client: HostClient } = require('discord-cross-hosting');
const config = require('./Config');

const hostclient = new HostClient({
    agent: config.web.agent,
    authToken: config.global.authToken,
    host: config.hosting.host,
    port: config.hosting.port,
});
hostclient
    .on('debug', m =>
        config.global.logLevel.debug ?
            console.debug(m)
            : ''
    )
    .on('ready', async d => {
        console.log(`Success! =>${ d.id } `);
    });

hostclient
    .connect()
    .then(async (hc) => {
        console.debug(hc)
        console.log(`WEB | Delay: ${ await hc.ping() }ms`);
    });

const express = require('express');

const app = express();
const port = config.web.port;

app.use('/home', require('./routes/home'));
app.use('/auth', require('./routes/auth'));
app.use('/dashboard', require('./routes/dashboard'));

app
    .get('', (req, res) => {
        return res.redirect('/home')
    })
    .get('/', (req, res) => {
        return res.redirect('/home')
    });

app.listen(port, async () => {
    console.log(`http://${ config.web.host }:${ config.web.port }`);
});