Skip to content

Commit d2e9b76

Browse files
suguru03BridgeAR
authored andcommitted
timers: fix setTimeout expiration logic
Fix the timer logic to be the same as v10.30.0. Fixes: #24203 PR-URL: #24214 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 3fe4498 commit d2e9b76

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function listOnTimeout(list, now) {
283283
// Check if this loop iteration is too early for the next timer.
284284
// This happens if there are more timers scheduled for later in the list.
285285
if (diff < msecs) {
286-
list.expiry = timer._idleStart + msecs;
286+
list.expiry = Math.max(timer._idleStart + msecs, now + 1);
287287
list.id = timerListId++;
288288
queue.percolateDown(1);
289289
debug('%d list wait because diff is %d', msecs, diff);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
/**
5+
* This test is for https://github.com/nodejs/node/issues/24203
6+
*/
7+
let count = 50;
8+
const time = 1.00000000000001;
9+
const exec = common.mustCall(() => {
10+
if (--count === 0) {
11+
return;
12+
}
13+
setTimeout(exec, time);
14+
}, count);
15+
exec();

0 commit comments

Comments
 (0)