From 7c871b6b85d7091bf6b2f9de7a2f160f9b9afb4b Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Sun, 5 Nov 2023 22:09:54 +0000 Subject: [PATCH] stream: wrap abort controller in try-catch --- src/modules/stream/types.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/stream/types.js b/src/modules/stream/types.js index 5c7fbdb8..2c1becee 100644 --- a/src/modules/stream/types.js +++ b/src/modules/stream/types.js @@ -6,6 +6,10 @@ import { request } from "undici"; import { create as contentDisposition } from "content-disposition-header"; import { AbortController } from "abort-controller" +function closeRequest(controller) { + try { controller.abort() } catch {} +} + function closeResponse(res) { if (!res.headersSent) res.sendStatus(500); return res.destroy(); @@ -21,7 +25,7 @@ function killProcess(p) { export async function streamDefault(streamInfo, res) { const abortController = new AbortController(); - const shutdown = () => (abortController.abort(), closeResponse(res)); + const shutdown = () => (closeRequest(abortController), closeResponse(res)); try { const filename = streamInfo.isAudioOnly ? `${streamInfo.filename}.${streamInfo.audioFormat}` : streamInfo.filename; @@ -45,7 +49,7 @@ export async function streamDefault(streamInfo, res) { export async function streamLiveRender(streamInfo, res) { let abortController = new AbortController(), process; - const shutdown = () => (abortController.abort(), killProcess(process), closeResponse(res)); + const shutdown = () => (closeRequest(abortController), killProcess(process), closeResponse(res)); try { if (streamInfo.urls.length !== 2) return shutdown();