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
@@ -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?.();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user