Skip to content

Commit

Permalink
rtp: fix leak if child process fails to spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Dec 23, 2024
1 parent 8ec6a25 commit e467414
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/webrtc/src/rtp-forwarders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export async function startRtpForwarderProcess(console: Console, ffmpegInput: FF

let rtspSdp: string;
const sdpDeferred = new Deferred<string>();
killDeferred.promise.finally(() => {
if (!sdpDeferred.finished)
sdpDeferred.reject(new Error('killed'));
});
const videoSectionDeferred = new Deferred<MSection>();
const audioSectionDeferred = new Deferred<MSection>();
videoSectionDeferred.promise.then(s => video?.onMSection?.(s));
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e467414

Please sign in to comment.