diff options
Diffstat (limited to 'lib/timers.js')
-rw-r--r-- | lib/timers.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/timers.js b/lib/timers.js index 0937e73c4a..14151d6d81 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -193,10 +193,13 @@ exports._unrefActive = function(item) { // Appends a timer onto the end of an existing timers list, or creates a new // list if one does not already exist for the specified timeout duration. function insert(item, refed, start) { - const msecs = item._idleTimeout; + let msecs = item._idleTimeout; if (msecs < 0 || msecs === undefined) return; + // Truncate so that accuracy of sub-milisecond timers is not assumed. + msecs = Math.trunc(msecs); + item._idleStart = start; // Use an existing list if there is one, otherwise we need to make a new one. @@ -378,7 +381,9 @@ function unenroll(item) { // clearTimeout that makes it clear that the list should not be deleted. // That function could then be used by http and other similar modules. if (item[kRefed]) { - const list = lists[item._idleTimeout]; + // Compliment truncation during insert(). + const msecs = Math.trunc(item._idleTimeout); + const list = lists[msecs]; if (list !== undefined && L.isEmpty(list)) { debug('unenroll: list empty'); queue.removeAt(list.priorityQueuePosition); |