Skip to content

Commit

Permalink
timers: fix setTimeout expiration logic
Browse files Browse the repository at this point in the history
Fix the timer logic to be the same as v10.30.0.

Fixes: #24203

PR-URL: #24214
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
suguru03 authored and BridgeAR committed Dec 5, 2018
1 parent 3fe4498 commit d2e9b76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function listOnTimeout(list, now) {
// Check if this loop iteration is too early for the next timer.
// This happens if there are more timers scheduled for later in the list.
if (diff < msecs) {
list.expiry = timer._idleStart + msecs;
list.expiry = Math.max(timer._idleStart + msecs, now + 1);
list.id = timerListId++;
queue.percolateDown(1);
debug('%d list wait because diff is %d', msecs, diff);
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-timers-timeout-with-non-integer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
const common = require('../common');

/**
* This test is for https://github.com/nodejs/node/issues/24203
*/
let count = 50;
const time = 1.00000000000001;
const exec = common.mustCall(() => {
if (--count === 0) {
return;
}
setTimeout(exec, time);
}, count);
exec();

0 comments on commit d2e9b76

Please sign in to comment.