Skip to content

setTimeout is not working properly with non-integer in Node 11 #24203

Closed
@suguru03

Description

@suguru03
  • Version: v11.1.0
  • Platform:Darwin suguru 17.7.0 Darwin Kernel Version 17.7.0: Fri Jul 6 19:54:51 PDT 2018; root:xnu-4570.71.3~2/RELEASE_X86_64 x86_64
  • Subsystem: timers

I have tested setTimeout and realized the function seems to have an issue when it is called with non-integer, such as 1.1 * 100 (110.00000000000001).
The function will stop calling a callback function randomly and eat up high CPU usage.
The code is as below,

const time = 1.1 * 100;
console.log(`time: ${time}`);

function exec(i) {
  console.log(i);
  setTimeout(exec, time, ++i);
}
exec(0);
// output
time: 110.00000000000001
0
1
2
3 // process hangs and eats up all CPU

I also tested it in Node v10, but it seems fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.timersIssues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions