rtp: fix leak if child process fails to spawn

This commit is contained in:
Koushik Dutta
2024-12-23 15:06:30 -08:00
parent 8ec6a25833
commit e467414704

View File

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