diff options
author | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2018-12-03 17:41:58 -0800 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2019-01-28 16:25:07 -0800 |
commit | a7c66b6aaeb8132540abee12ffa9ac1c1fa2f373 (patch) | |
tree | 564283992698f1a73604169deb15d458041565d7 /lib/timers.js | |
parent | a0419dd8ca66733e7a4592d98d4f4ebe2f2762e3 (diff) | |
download | android-node-v8-a7c66b6aaeb8132540abee12ffa9ac1c1fa2f373.tar.gz android-node-v8-a7c66b6aaeb8132540abee12ffa9ac1c1fa2f373.tar.bz2 android-node-v8-a7c66b6aaeb8132540abee12ffa9ac1c1fa2f373.zip |
timers: truncate decimal values
Reverts some timers behavior back to as it was before
2930bd1317d15d12738a4896c0a6c05700411b47
That commit introduced an unintended change which allowed non-integer
timeouts to actually exist since the value is no longer converted to an
integer via a TimeWrap handle directly.
Even with the fix in
e9de43549843da9f4f081cce917945878967df7
non-integer timeouts are still indeterministic, because libuv does not
support them.
This fixes the issue by emulating the old behavior:
truncate the `_idleTimeout` before using it.
See comments in
https://github.com/nodejs/node/pull/24214
for more background on this.
PR-URL: https://github.com/nodejs/node/pull/24819
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
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); |