fix(gateway): crash safety on screen-share input timeout + proper error serialization
Root cause of "langsung left": YouTube bot-block/403 on u_c1tRmj7E4 (live
stream, LOGIN_REQUIRED) made yt-dlp timeout in resolveInputWithRetry (12s).
The timeout handler did cleanup() (removing once() listeners) THEN
tee.destroy(new Error(...)) — the PassThrough emitted 'error' with NO
listener left → unhandled stream 'error' event → uncaughtException →
gracefulShutdown → bot left voice.
Fix:
- resolveInputWithRetry: tee.destroy() silently after cleanup (error carried
in the rejection only); add permanent no-op tee.on('error') safety.
- prepareStream: output.on('error') no-op so ffmpeg spawn failure before
playStream attaches a demux listener never crashes the gateway.
- bootstrap: serialize uncaughtException/ClientError/DB errors with
{err, errorMsg, stack} (pino only serializes the 'err' magic key — the old
{error: err} key printed {} so crashes were invisible).
This commit is contained in:
@@ -93,11 +93,11 @@ export class ScreenShareController {
|
||||
const timer = setTimeout(() => {
|
||||
cleanup();
|
||||
destroyInput();
|
||||
tee.destroy(
|
||||
new Error(
|
||||
"Screen input produced no data within 12s — merge likely failed",
|
||||
),
|
||||
);
|
||||
// Listeners were just removed by cleanup() — destroying tee WITH
|
||||
// an error would emit "error" on an unlistened PassThrough and
|
||||
// surface as an unhandled 'error' event (crash). Destroy
|
||||
// silently; the error lives in the rejection only.
|
||||
tee.destroy();
|
||||
reject(
|
||||
new Error(
|
||||
"Screen input produced no data within 12s — merge likely failed",
|
||||
@@ -131,6 +131,11 @@ export class ScreenShareController {
|
||||
tee.once("end", onEnd);
|
||||
});
|
||||
|
||||
// Safety net: cleanup() removes the once() listeners on timeout/error,
|
||||
// but a late error event from input.pipe(tee) can still fire on an
|
||||
// unlistened PassThrough and crash the gateway (unhandled 'error').
|
||||
// A permanent no-op listener guarantees the event is always swallowed.
|
||||
tee.on("error", () => {});
|
||||
// Pass the tee onward — the encoder consumes the same buffered
|
||||
// stream, so no data from the merge is lost.
|
||||
return tee;
|
||||
|
||||
Reference in New Issue
Block a user