From 09580cebf53fbbf0dcda47369d7f6cc1a4a754e9 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Fri, 8 May 2026 00:16:14 +0300 Subject: [PATCH] dashboard --- src/dashboard/Dashboard.mjs | 16 +++++++++++++--- src/dashboard/RedisHandler.mjs | 26 +++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/dashboard/Dashboard.mjs b/src/dashboard/Dashboard.mjs index 61d6525..126194a 100644 --- a/src/dashboard/Dashboard.mjs +++ b/src/dashboard/Dashboard.mjs @@ -41,9 +41,15 @@ export class Dashboard { } case "sharedServers": { - const sharedUser = await this.remix.client.users.fetch(data.key).catch(() => null); - if (!sharedUser) return { error: "User not found" }; - return await this.remix.getSharedServers(sharedUser); + try { + const sharedUser = await this.remix.client.users.fetch(data.key).catch(() => null); + if (!sharedUser) return { error: "User not found" }; + return await this.remix.getSharedServers(sharedUser); + } catch (e) { + const id = Utils.uid(); + logger.dashboard("[Dashboard] sharedServers error:", id, e); + return { error: "Failed to fetch shared servers. Id: " + id }; + } } case "server": { @@ -73,6 +79,10 @@ export class Dashboard { case "function": return await this.runFunction(data.params); + + default: + logger.dashboard("[Dashboard] Unknown request type:", data.type); + return { error: "Unknown request type: " + (data.type ?? "(none)") }; } }); } diff --git a/src/dashboard/RedisHandler.mjs b/src/dashboard/RedisHandler.mjs index 859e09d..4e2ad76 100644 --- a/src/dashboard/RedisHandler.mjs +++ b/src/dashboard/RedisHandler.mjs @@ -61,7 +61,9 @@ export class RedisHandler { try { await this.client.connect(); logger.redis("[Redis/Main] Connected"); - this.readyMessage(); + // Do NOT call readyMessage() here — the subscriber is not yet listening + // on the "request" channel. If we announce before subscribing, the + // backend will send requests that we miss, causing a timeout. } catch (e) { logger.error("[Redis/Main] Initial connection failed:", e.message); } @@ -70,7 +72,10 @@ export class RedisHandler { await this.subscriber.connect(); logger.redis("[Redis/Subscriber] Connected"); - this.subscriber.subscribe("request", async (m) => { + // CRITICAL: Await both subscriptions so they are guaranteed to be active + // before we announce readiness. Without awaiting, there is a window + // where the backend sends requests that this bot cannot yet receive. + await this.subscriber.subscribe("request", async (m) => { if (this._destroyed) return; try { const payload = JSON.parse(m); @@ -83,10 +88,20 @@ export class RedisHandler { })); } catch (e) { logger.error("[Redis/Subscriber] Request handler error:", e.message); + // Always send a response so the backend doesn't time out. + // Parse the id from the raw message so we can reply even when + // the handler threw before producing a result. + try { + const payload = JSON.parse(m); + this.send("response", JSON.stringify({ + id: payload.id, + content: { error: "Internal bot error: " + e.message }, + })); + } catch (_) { /* payload was unparseable — nothing we can do */ } } }); - this.subscriber.subscribe("info", (m) => { + await this.subscriber.subscribe("info", (m) => { if (this._destroyed) return; try { const data = JSON.parse(m); @@ -97,6 +112,11 @@ export class RedisHandler { logger.warn("[Redis/Subscriber] Info handler error:", e.message); } }); + + // NOW announce readiness — the subscriber is guaranteed to be listening + // on both "request" and "info", so the backend's requests will be + // received and handled. + this.readyMessage(); } catch (e) { logger.error("[Redis/Subscriber] Initial connection failed:", e.message); }