From e467414704dceb7e786f91c39ae3301eb7fcdc6e Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 23 Dec 2024 15:06:30 -0800 Subject: [PATCH] rtp: fix leak if child process fails to spawn --- plugins/webrtc/src/rtp-forwarders.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/webrtc/src/rtp-forwarders.ts b/plugins/webrtc/src/rtp-forwarders.ts index e2637e5a08..db21579130 100644 --- a/plugins/webrtc/src/rtp-forwarders.ts +++ b/plugins/webrtc/src/rtp-forwarders.ts @@ -157,6 +157,10 @@ export async function startRtpForwarderProcess(console: Console, ffmpegInput: FF let rtspSdp: string; const sdpDeferred = new Deferred(); + killDeferred.promise.finally(() => { + if (!sdpDeferred.finished) + sdpDeferred.reject(new Error('killed')); + }); const videoSectionDeferred = new Deferred(); const audioSectionDeferred = new Deferred(); videoSectionDeferred.promise.then(s => video?.onMSection?.(s)); @@ -279,6 +283,7 @@ export async function startRtpForwarderProcess(console: Console, ffmpegInput: FF ffmpegLogInitialOutput(console, cp); killDeferred.promise.finally(() => safeKillFFmpeg(cp)); cp.on('exit', () => killDeferred.resolve(undefined)); + cp.on('error', () => killDeferred.resolve(undefined)); audioPipe = cp.stdio[3] as Writable; } @@ -489,6 +494,10 @@ export async function startRtpForwarderProcess(console: Console, ffmpegInput: FF if (!allowAudioTranscoderExit) killDeferred.resolve(undefined); }); + cp.on('error', () => { + if (!allowAudioTranscoderExit) + killDeferred.resolve(undefined); + }); if (pipeSdp) { const pipe = cp.stdio[3] as Writable; pipe.write(pipeSdp);