stream: send SIGKILL after timeout
in case the ffmpeg process decides to hang when SIGTERM'd
This commit is contained in:
parent
cae4a68aa4
commit
dbd13bc8b6
1 changed files with 11 additions and 3 deletions
|
@ -11,6 +11,14 @@ function closeResponse(res) {
|
||||||
return res.destroy();
|
return res.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function killProcess(p) {
|
||||||
|
p?.kill();
|
||||||
|
setTimeout(() => {
|
||||||
|
if (p?.exitCode === null)
|
||||||
|
p?.kill(9);
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
export async function streamDefault(streamInfo, res) {
|
export async function streamDefault(streamInfo, res) {
|
||||||
const abortController = new AbortController();
|
const abortController = new AbortController();
|
||||||
const shutdown = () => (abortController.abort(), closeResponse(res));
|
const shutdown = () => (abortController.abort(), closeResponse(res));
|
||||||
|
@ -37,7 +45,7 @@ export async function streamDefault(streamInfo, res) {
|
||||||
|
|
||||||
export async function streamLiveRender(streamInfo, res) {
|
export async function streamLiveRender(streamInfo, res) {
|
||||||
let abortController = new AbortController(), process;
|
let abortController = new AbortController(), process;
|
||||||
const shutdown = () => (abortController.abort(), process?.kill(), closeResponse(res));
|
const shutdown = () => (abortController.abort(), killProcess(process), closeResponse(res));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (streamInfo.urls.length !== 2) return shutdown();
|
if (streamInfo.urls.length !== 2) return shutdown();
|
||||||
|
@ -85,7 +93,7 @@ export async function streamLiveRender(streamInfo, res) {
|
||||||
|
|
||||||
export function streamAudioOnly(streamInfo, res) {
|
export function streamAudioOnly(streamInfo, res) {
|
||||||
let process;
|
let process;
|
||||||
const shutdown = () => (process?.kill(), closeResponse(res));
|
const shutdown = () => (killProcess(process), closeResponse(res));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let args = [
|
let args = [
|
||||||
|
@ -132,7 +140,7 @@ export function streamAudioOnly(streamInfo, res) {
|
||||||
|
|
||||||
export function streamVideoOnly(streamInfo, res) {
|
export function streamVideoOnly(streamInfo, res) {
|
||||||
let process;
|
let process;
|
||||||
const shutdown = () => (process?.kill(), closeResponse(res));
|
const shutdown = () => (killProcess(process), closeResponse(res));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [
|
let format = streamInfo.filename.split('.')[streamInfo.filename.split('.').length - 1], args = [
|
||||||
|
|
Loading…
Reference in a new issue