Skip to content

Commit 2afaaa3

Browse files
committed
fix(jobprocessor): check if set timeout value is valid
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.
1 parent b877823 commit 2afaaa3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/JobProcessor.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const log = debug('agenda:jobProcessor');
1111
// eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
1212
const { version: agendaVersion } = require('../package.json');
1313

14+
const MAX_SAFE_32BIT_INTEGER = 2 ** 31; // Math.pow(2,31);
15+
1416
/**
1517
* @class
1618
* Process methods for jobs
@@ -428,9 +430,13 @@ export class JobProcessor {
428430
);
429431
// re add to queue (puts it at the right position in the queue)
430432
this.jobQueue.insert(job);
431-
setTimeout(() => {
432-
this.jobProcessing();
433-
}, runIn);
433+
setTimeout(
434+
() => {
435+
this.jobProcessing();
436+
},
437+
runIn > MAX_SAFE_32BIT_INTEGER ? MAX_SAFE_32BIT_INTEGER : runIn
438+
); // check if runIn is higher than unsined 32 bit int, if so, use this time to recheck,
439+
// because setTimeout will run in an overflow otherwise and reprocesses immediately
434440
}
435441
}
436442

0 commit comments

Comments
 (0)