From bfc99125d3d1885c01254d47b6403c2efe9df32a Mon Sep 17 00:00:00 2001 From: decompi Date: Mon, 24 Mar 2025 21:09:25 -0400 Subject: [PATCH] Fix: prevent crash when stdoutRing or stderrRing is undefined --- lib/processor.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/processor.js b/lib/processor.js index 36d980ad..7c096a7f 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -467,7 +467,11 @@ module.exports = function(proto) { self.processTimer = setTimeout(function() { var msg = 'process ran into a timeout (' + self.options.timeout + 's)'; - emitEnd(new Error(msg), stdoutRing.get(), stderrRing.get()); + if (!stdoutRing || !stderrRing) { + self.logger?.warn?.('stdoutRing or stderrRing is undefined during timeout.'); + } + + emitEnd( new Error(msg), stdoutRing?.get?.() ?? null, stderrRing?.get?.() ?? null ); ffmpegProc.kill(); }, self.options.timeout * 1000); } @@ -495,7 +499,10 @@ module.exports = function(proto) { self.logger.debug('Output stream error, killing ffmpeg process'); var reportingErr = new Error('Output stream error: ' + err.message); reportingErr.outputStreamError = err; - emitEnd(reportingErr, stdoutRing.get(), stderrRing.get()); + if (!stdoutRing || !stderrRing) { + self.logger?.warn?.('stdoutRing or stderrRing is undefined during output stream error.'); + } + emitEnd( reportingErr, stdoutRing?.get?.() ?? null, stderrRing?.get?.() ?? null ); ffmpegProc.kill('SIGKILL'); }); } @@ -540,7 +547,11 @@ module.exports = function(proto) { err.message += ': ' + utils.extractError(stderrRing.get()); } - emitEnd(err, stdoutRing.get(), stderrRing.get()); + if(!stdoutRing || !stderrRing) { + self.logger?.warn?.('stdoutRing or stderrRing is undefined – FFmpeg may have exited early.') + } + + emitEnd( err, stdoutRing?.get?.() ?? null, stderrRing?.get?.() ?? null ); } else { // Find out which outputs need flv metadata var flvmeta = self._outputs.filter(function(output) {