mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
fix(voice, music): resolve thundering herd rejoins, playback drop recovery, and telemetry warnings
- Stagger simultaneous 24/7 channel rejoins (+2.5s per pending channel) and defer rejoins when the gateway is not connected - Add in-place voice reconnection recovery during track playback to prevent burning through queue songs on transient LiveKit disconnects - Fix audio publication race on seek by removing redundant bridge stop and increasing unpublish timeout to 2,500ms - Eliminate duplicate voice reconnect races in Player disconnect handler for 24/7 channels - De-escalate routine background reconnect logs from logger.warn/error to logger.voice247/player to stop spurious Discord warning embeds - Sanitize upstream Cloudflare/Fluxer 503 HTML error pages into single-line messages in ErrorChannel
This commit is contained in:
1 parent
8b99bd01dc
commit
cc07c35f2a
6 files changed
+53
-13
No files matched your search
@@ -9,7 +9,6 @@
|
||||
import { CommandBuilder } from "../src/commands/index.mjs";
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { getMessageGuildId, getGlobalColor } from "../src/ui/index.mjs";
|
||||
import { logger } from "../src/core/Logger.mjs";
|
||||
import {
|
||||
SHORTCUTS, BOOL_SETTINGS, VALID_LOCALES, setValidLocales,
|
||||
VOLUME_MIN, VOLUME_MAX,
|
||||
|
||||
@@ -203,7 +203,9 @@ const BotVoiceMixin = {
|
||||
if (!this._247RejoinTimers) this._247RejoinTimers = new Map();
|
||||
if (this._247RejoinTimers.has(cleanCh)) return;
|
||||
|
||||
const delay = delayMs ?? this.config?.timers?.rejoin247Delay ?? 3_000;
|
||||
/* Stagger multiple simultaneous rejoins to avoid overwhelming the gateway and LiveKit */
|
||||
const stagger = (this._247RejoinTimers.size) * 2_500;
|
||||
const delay = delayMs ?? ((this.config?.timers?.rejoin247Delay ?? 3_000) + stagger);
|
||||
logger.voice247(`[247] Arming bot-level rejoin for ${cleanCh} (guild ${cleanG}) in ${delay / 1000}s`);
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
@@ -212,13 +214,19 @@ const BotVoiceMixin = {
|
||||
logger.voice247(`[247] Rejoin for ${cleanCh} cancelled — intentional leave registered`);
|
||||
return;
|
||||
}
|
||||
/* Defer if gateway is reconnecting or down — voice join requires an active gateway connection */
|
||||
if (this._gatewayConnected === false) {
|
||||
logger.voice247(`[247] Gateway not connected yet — deferring rejoin for ${cleanCh} by 5s`);
|
||||
this.schedule247Rejoin(cleanCh, cleanG, 5_000);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const p = this.gatewayHandler?._rejoinChannel?.(cleanG, cleanCh);
|
||||
if (p && typeof p.catch === "function") {
|
||||
p.catch(err => logger.warn(`[247] Rejoin failed for channel ${cleanCh}:`, err?.message ?? err));
|
||||
p.catch(err => logger.voice247(`[247] Rejoin failed for channel ${cleanCh}:`, err?.message ?? err));
|
||||
}
|
||||
} catch (err) {
|
||||
logger.warn(`[247] Rejoin failed for channel ${cleanCh}:`, err?.message ?? err);
|
||||
logger.voice247(`[247] Rejoin failed for channel ${cleanCh}:`, err?.message ?? err);
|
||||
}
|
||||
}, delay);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ const TRACK_KIND_AUDIO = 1;
|
||||
const pendingUnpublishSids = new WeakMap();
|
||||
|
||||
/** @type {number} @description Max time to wait for a stale-track unpublish to settle before publishing anyway (defensive — an unpublish should resolve almost instantly; this only guards against a hung/never-resolving LiveKit promise blocking playback indefinitely). */
|
||||
const UNPUBLISH_WAIT_TIMEOUT_MS = 1200;
|
||||
const UNPUBLISH_WAIT_TIMEOUT_MS = 2500;
|
||||
|
||||
/** @extends {EventEmitter} */
|
||||
export class FluxerAudioBridge extends EventEmitter {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { ERROR_COLOR } from "../../utils/UI.mjs";
|
||||
import { Utils, cleanId } from "../../utils/Utils.mjs";
|
||||
import { isPlayerConnectionDead } from "../../utils/Helpers247.mjs";
|
||||
import { logger } from "../../core/Logger.mjs";
|
||||
import { getBilibiliStreamUrl } from "../bilibili/index.mjs";
|
||||
|
||||
@@ -293,7 +294,32 @@ const PlaybackMixin = {
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error("[Player] Play error:", err.message);
|
||||
const errMsg = err?.message ?? String(err);
|
||||
logger.error("[Player] Play error:", errMsg);
|
||||
|
||||
/* In-place recovery if playback failed due to a lost or dead voice connection */
|
||||
const isVoiceLost = isPlayerConnectionDead(this)
|
||||
|| /track publication timed out|No voice connection|Voice connection timeout/i.test(errMsg);
|
||||
|
||||
if (isVoiceLost && !this.leaving && !this._destroyed) {
|
||||
logger.player(`[Player:${this._guildId}] Voice connection lost during playback — attempting in-place voice recovery`);
|
||||
const cId = cleanId(this._channelId ?? this._home247Channel ?? "");
|
||||
if (cId) {
|
||||
this._voiceConn = null;
|
||||
this.connection = null;
|
||||
try {
|
||||
await this.join(cId);
|
||||
if (this._voiceConn) {
|
||||
this._consecutiveErrors = 0;
|
||||
await this._playTrackViaBridge(songData, { seekSeconds: seekSec });
|
||||
return;
|
||||
}
|
||||
} catch (recErr) {
|
||||
logger.player(`[Player:${this._guildId}] In-place voice recovery failed: ${recErr?.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._skipping && !this.leaving && !this._paused && songData.type !== "radio") {
|
||||
const pfx = this._getPrefix?.(this._guildId) ?? "%";
|
||||
const playErrEmbed = new EmbedBuilder()
|
||||
@@ -537,7 +563,6 @@ const PlaybackMixin = {
|
||||
this._seeking = true;
|
||||
|
||||
try {
|
||||
this._bridgeStop();
|
||||
const current = this.queue.getCurrent();
|
||||
if (current?.url) {
|
||||
this.startedPlaying = Date.now() - ms;
|
||||
@@ -550,7 +575,7 @@ const PlaybackMixin = {
|
||||
return true;
|
||||
} catch (e) {
|
||||
this._seeking = false;
|
||||
logger.error("[Player] Seek failed:", e?.message);
|
||||
logger.player(`[Player] Seek failed: ${e?.message ?? e}`);
|
||||
return false;
|
||||
} finally {
|
||||
this._seeking = false;
|
||||
|
||||
@@ -607,9 +607,17 @@ class Player extends EventEmitter {
|
||||
this._voiceConn = null;
|
||||
this.connection = null;
|
||||
const cId = cleanId(this._channelId ?? this._home247Channel ?? "");
|
||||
if (cId && (this._get247Mode() === "on" || this.queue?.getCurrent() || !(this.queue?.isEmpty?.() ?? true))) {
|
||||
logger.player(`[Player] Voice disconnected with active session — scheduling reconnect to channel ${cId}`);
|
||||
this.join(cId).catch(err => logger.warn(`[Player] Voice reconnect after disconnect failed: ${err?.message}`));
|
||||
const is247 = this._get247Mode() === "on";
|
||||
if (is247) {
|
||||
/* 24/7 channels are managed centrally by GatewayHandler and schedule247Rejoin to prevent race conditions */
|
||||
return;
|
||||
}
|
||||
if (cId && (this.queue?.getCurrent() || !(this.queue?.isEmpty?.() ?? true))) {
|
||||
logger.player(`[Player] Voice disconnected with active session — scheduling reconnect to channel ${cId} in 2.5s`);
|
||||
setTimeout(() => {
|
||||
if (this.leaving || this._destroyed || this._voiceConn) return;
|
||||
this.join(cId).catch(err => logger.player(`[Player] Voice reconnect after disconnect failed: ${err?.message}`));
|
||||
}, 2_500).unref?.();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ const RejoinManager = {
|
||||
|
||||
if (isTransientError && attempt < maxRetries) {
|
||||
const backoffMs = baseDelay * Math.pow(2, attempt - 1);
|
||||
logger.warn(
|
||||
logger.voice247(
|
||||
`[${context}] Voice connection/track failed for channel ${channelId} (attempt ${attempt}/${maxRetries}) — ` +
|
||||
`retrying in ${backoffMs / 1000}s: ${errMsg}`
|
||||
);
|
||||
@@ -74,7 +74,7 @@ const RejoinManager = {
|
||||
`[${context}] Background rejoin failed for channel ${channelId} (failure #${failCount + 1}): ${errMsg} — keeping 24/7 setting intact.`
|
||||
);
|
||||
} else {
|
||||
logger.warn(
|
||||
logger.voice247(
|
||||
`[${context}] Failed to rejoin channel ${channelId}: ${errMsg} — keeping 24/7 setting intact.`
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user