stream: send SIGKILL after timeout

in case the ffmpeg process decides to hang when SIGTERM'd
This commit is contained in:
dumbmoron 2023-11-05 22:07:34 +00:00
parent 9001d401da
commit 1508a0bff4
No known key found for this signature in database
GPG key ID: C59997C76C6A8E5F

View file

@ -11,6 +11,14 @@ function closeResponse(res) {
return res.destroy();
}
function killProcess(p) {
p?.kill();
setTimeout(() => {
if (p?.exitCode === null)
p?.kill(9);
}, 5000);
}
export async function streamDefault(streamInfo, res) {
const abortController = new AbortController();
const shutdown = () => (abortController.abort(), closeResponse(res));
@ -37,7 +45,7 @@ export async function streamDefault(streamInfo, res) {
export async function streamLiveRender(streamInfo, res) {
let abortController = new AbortController(), process;
const shutdown = () => (abortController.abort(), process?.kill(), closeResponse(res));
const shutdown = () => (abortController.abort(), killProcess(process), closeResponse(res));
try {
if (streamInfo.urls.length !== 2) return shutdown();
@ -85,7 +93,7 @@ export async function streamLiveRender(streamInfo, res) {
export function streamAudioOnly(streamInfo, res) {
let process;
const shutdown = () => (process?.kill(), closeResponse(res));
const shutdown = () => (killProcess(process), closeResponse(res));
try {
let args = [
@ -132,7 +140,7 @@ export function streamAudioOnly(streamInfo, res) {
export function streamVideoOnly(streamInfo, res) {
let process;
const shutdown = () => (process?.kill(), closeResponse(res));
const shutdown = () => (killProcess(process), closeResponse(res));
try {
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [