Skip to content

Commit

Permalink
fix(jobprocessor): check if set timeout value is valid
Browse files Browse the repository at this point in the history
see agenda/agenda#1146

no case to reproduce this issue, but could be theoretically the case if the checkInterval is super high or a job is in the queue for a very long time.
  • Loading branch information
simllll committed Nov 18, 2020
1 parent b877823 commit 2afaaa3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/JobProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const log = debug('agenda:jobProcessor');
// eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
const { version: agendaVersion } = require('../package.json');

const MAX_SAFE_32BIT_INTEGER = 2 ** 31; // Math.pow(2,31);

/**
* @class
* Process methods for jobs
Expand Down Expand Up @@ -428,9 +430,13 @@ export class JobProcessor {
);
// re add to queue (puts it at the right position in the queue)
this.jobQueue.insert(job);
setTimeout(() => {
this.jobProcessing();
}, runIn);
setTimeout(
() => {
this.jobProcessing();
},
runIn > MAX_SAFE_32BIT_INTEGER ? MAX_SAFE_32BIT_INTEGER : runIn
); // check if runIn is higher than unsined 32 bit int, if so, use this time to recheck,
// because setTimeout will run in an overflow otherwise and reprocesses immediately
}
}

Expand Down

0 comments on commit 2afaaa3

Please sign in to comment.