This commit is contained in:
NoLogicAlan committed 2026-09-01 02:43:24 +03:00
1 parent a5d24dfc93
commit 250066da8b
2 files changed
+32 -2

No files matched your search

+16
View File
@@ -1055,6 +1055,13 @@ const isIgnorableWsCrash = (err) => {
const isBenignAudioStopRace = (err) => const isBenignAudioStopRace = (err) =>
String(err?.message ?? err ?? "").includes("AudioSource is closed"); String(err?.message ?? err ?? "").includes("AudioSource is closed");
/**
* @param {Error} err - The error to check.
* @returns {boolean} True if the error is the stream abort race.
*/
const isBenignStreamAbortRace = (err) =>
err?.code === "ECONNRESET" && String(err?.message ?? "").includes("aborted");
let _lastWsCrashLog = 0; let _lastWsCrashLog = 0;
let _lastAudioRaceLog = 0; let _lastAudioRaceLog = 0;
const WS_CRASH_LOG_COOLDOWN = 30_000; const WS_CRASH_LOG_COOLDOWN = 30_000;
@@ -1081,6 +1088,14 @@ process.on("uncaughtException", (err, origin) => {
} }
return; return;
} }
if (isBenignStreamAbortRace(err)) {
const now = Date.now();
if (now - _lastAudioRaceLog > WS_CRASH_LOG_COOLDOWN) {
_lastAudioRaceLog = now;
logger.warn("[Error_Handling] Suppressed benign stream abort race (aborted/ECONNRESET) — loadstream was destroyed mid-transfer.");
}
return;
}
logger.error("[Error_Handling] Uncaught Exception/Catch"); logger.error("[Error_Handling] Uncaught Exception/Catch");
logger.error("Error:", err, origin); logger.error("Error:", err, origin);
process.exit(1); process.exit(1);
@@ -1088,6 +1103,7 @@ process.on("uncaughtException", (err, origin) => {
process.on("uncaughtExceptionMonitor", (err, origin) => { process.on("uncaughtExceptionMonitor", (err, origin) => {
if (isIgnorableWsCrash(err)) return; if (isIgnorableWsCrash(err)) return;
if (isBenignAudioStopRace(err)) return; if (isBenignAudioStopRace(err)) return;
if (isBenignStreamAbortRace(err)) return;
logger.error("[Error_Handling] Uncaught Exception/Catch (MONITOR)"); logger.error("[Error_Handling] Uncaught Exception/Catch (MONITOR)");
logger.error("Error:", err, origin); logger.error("Error:", err, origin);
}); });
+16 -2
View File
@@ -45,6 +45,7 @@ export class FluxerAudioBridge extends EventEmitter {
_stream = null; _stream = null;
_encoder = null; _encoder = null;
_sourceStream = null; _sourceStream = null;
_sourceReq = null;
_playing = false; _playing = false;
_stopped = false; _stopped = false;
_startedAt = 0; _startedAt = 0;
@@ -172,6 +173,7 @@ export class FluxerAudioBridge extends EventEmitter {
const routed = await this._routeByMagic(loaded.stream); const routed = await this._routeByMagic(loaded.stream);
this._sourceStream = loaded.stream; this._sourceStream = loaded.stream;
this._sourceReq = loaded.req || null;
if (routed.kind === "webm") { if (routed.kind === "webm") {
logger.player("[AudioBridge] Playing loadstream webm/opus passthrough: " + (trackInfo.title || "unknown") + logger.player("[AudioBridge] Playing loadstream webm/opus passthrough: " + (trackInfo.title || "unknown") +
@@ -268,6 +270,7 @@ export class FluxerAudioBridge extends EventEmitter {
const routed2 = await this._routeByMagic(loaded.stream); const routed2 = await this._routeByMagic(loaded.stream);
this._sourceStream = loaded.stream; this._sourceStream = loaded.stream;
this._sourceReq = loaded.req || null;
if (routed2.kind === "webm") { if (routed2.kind === "webm") {
logger.player("[AudioBridge] Route 3c (Lavalink): webm/opus passthrough"); logger.player("[AudioBridge] Route 3c (Lavalink): webm/opus passthrough");
@@ -664,6 +667,9 @@ export class FluxerAudioBridge extends EventEmitter {
}); });
}); });
req.on("socket", (socket) => {
socket.on("error", () => {});
});
req.on("error", reject); req.on("error", reject);
req.setTimeout(timeoutMs, () => { req.setTimeout(timeoutMs, () => {
req.destroy(); req.destroy();
@@ -677,7 +683,7 @@ export class FluxerAudioBridge extends EventEmitter {
* @param {string} url * @param {string} url
* @param {object} [headers] * @param {object} [headers]
* @param {number} [_redirectCount=0] * @param {number} [_redirectCount=0]
* @returns {Promise<{stream: Readable, inputFormat: string|null}>} * @returns {Promise<{stream: Readable, inputFormat: string|null, req: http.ClientRequest}>}
* @private * @private
*/ */
_httpRequestStream(url, headers = {}, _redirectCount = 0) { _httpRequestStream(url, headers = {}, _redirectCount = 0) {
@@ -739,7 +745,11 @@ export class FluxerAudioBridge extends EventEmitter {
res.once("data", () => resetIdleTimeout()); res.once("data", () => resetIdleTimeout());
logger.player("[AudioBridge] loadstream response: " + res.statusCode + " content-type=" + (res.headers["content-type"] || "?")); logger.player("[AudioBridge] loadstream response: " + res.statusCode + " content-type=" + (res.headers["content-type"] || "?"));
resolve({ stream: res, inputFormat: res.headers["content-type"] || null }); resolve({ stream: res, inputFormat: res.headers["content-type"] || null, req });
});
req.on("socket", (socket) => {
socket.on("error", () => {});
}); });
req.on("error", (err) => { req.on("error", (err) => {
@@ -850,9 +860,13 @@ export class FluxerAudioBridge extends EventEmitter {
try { s.destroy(); } catch (_) {} try { s.destroy(); } catch (_) {}
} }
} }
if (this._sourceReq) {
try { this._sourceReq.destroy(); } catch (_) {}
}
this._stream = null; this._stream = null;
this._encoder = null; this._encoder = null;
this._sourceStream = null; this._sourceStream = null;
this._sourceReq = null;
} }
/** Stop playback, release the voice connection, and remove all listeners. */ /** Stop playback, release the voice connection, and remove all listeners. */