Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit a9ebbd3

Browse files
committed
Clear process timeout timer when command completes
Otherwise the timer needlessly keeps the node process alive.
1 parent 22db625 commit a9ebbd3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/processor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,8 @@ module.exports = function(proto) {
464464
}
465465

466466
// Setup timeout if requested
467-
var processTimer;
468467
if (self.options.timeout) {
469-
processTimer = setTimeout(function() {
468+
self.processTimer = setTimeout(function() {
470469
var msg = 'process ran into a timeout (' + self.options.timeout + 's)';
471470

472471
emitEnd(new Error(msg), stdoutRing.get(), stderrRing.get());
@@ -533,6 +532,7 @@ module.exports = function(proto) {
533532
},
534533

535534
function endCB(err, stdoutRing, stderrRing) {
535+
clearTimeout(self.processTimer);
536536
delete self.ffmpegProc;
537537

538538
if (err) {

test/processor.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@ describe('Processor', function() {
280280
.saveToFile(testFile);
281281
});
282282

283+
it('should not keep node process running on completion', function(done) {
284+
var script = `
285+
var ffmpeg = require('.');
286+
ffmpeg('${this.testfilebig}', { timeout: 60 })
287+
.addOption('-t', 1)
288+
.addOption('-f', 'null')
289+
.saveToFile('/dev/null');
290+
`;
291+
292+
exec(`node -e "${script}"`, { timeout: 1000 }, done);
293+
});
294+
283295
it('should kill the process with .kill', function(done) {
284296
var testFile = path.join(__dirname, 'assets', 'testProcessKill.avi');
285297
this.files.push(testFile);

0 commit comments

Comments
 (0)