Skip to content

Commit 568b6a5

Browse files
committed
timers: be more defensive with intervals
It's possible for user-code to flip an existing timeout to be an interval during its execution, in which case the current code would crash due to start being undefined. Fix this by providing a default start value within rearm. PR-URL: #18579 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 1b05d7b commit 568b6a5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/timers.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ function ontimeout(timer, start) {
442442
rearm(timer, start);
443443
}
444444

445-
446-
function rearm(timer, start) {
445+
function rearm(timer, start = TimerWrap.now()) {
447446
// // Do not re-arm unenroll'd or closed timers.
448447
if (timer._idleTimeout === -1) return;
449448

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// This isn't officially supported but nonetheless is something that is
5+
// currently possible and as such it shouldn't cause the process to crash
6+
7+
const t = setTimeout(common.mustCall(() => {
8+
if (t._repeat) {
9+
clearInterval(t);
10+
}
11+
t._repeat = true;
12+
}, 2), 1);

0 commit comments

Comments
 (0)