stream: wrap abort controller in try-catch

This commit is contained in:
dumbmoron 2023-11-05 22:09:54 +00:00
parent 1508a0bff4
commit ed646b826d
No known key found for this signature in database
GPG key ID: C59997C76C6A8E5F

View file

@ -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();