Skip to content

Commit

Permalink
Clear process timeout timer when command completes
Browse files Browse the repository at this point in the history
Otherwise the timer needlessly keeps the node process alive.
  • Loading branch information
c24w committed Jul 9, 2019
1 parent 22db625 commit a9ebbd3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,8 @@ module.exports = function(proto) {
}

// Setup timeout if requested
var processTimer;
if (self.options.timeout) {
processTimer = setTimeout(function() {
self.processTimer = setTimeout(function() {
var msg = 'process ran into a timeout (' + self.options.timeout + 's)';

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

function endCB(err, stdoutRing, stderrRing) {
clearTimeout(self.processTimer);
delete self.ffmpegProc;

if (err) {
Expand Down
12 changes: 12 additions & 0 deletions test/processor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,18 @@ describe('Processor', function() {
.saveToFile(testFile);
});

it('should not keep node process running on completion', function(done) {
var script = `
var ffmpeg = require('.');
ffmpeg('${this.testfilebig}', { timeout: 60 })
.addOption('-t', 1)
.addOption('-f', 'null')
.saveToFile('/dev/null');
`;

exec(`node -e "${script}"`, { timeout: 1000 }, done);
});

it('should kill the process with .kill', function(done) {
var testFile = path.join(__dirname, 'assets', 'testProcessKill.avi');
this.files.push(testFile);
Expand Down

0 comments on commit a9ebbd3

Please sign in to comment.