Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setTimeout bug. There is example #8354

Closed
alsotang opened this issue Aug 31, 2016 · 7 comments
Closed

setTimeout bug. There is example #8354

alsotang opened this issue Aug 31, 2016 · 7 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

Comments

@alsotang
Copy link

alsotang commented Aug 31, 2016

  • Version:4.2.1, 5.9.0, 6.0.0
  • Platform: macos
  • Subsystem:
var startTime = +new Date()
while ((new Date - startTime) < 1000) {}

setTimeout(function () {
  var startTime = +new Date()
  while ((new Date - startTime) < 3000) {}

  var t1= new Date
  setTimeout(function () {
    console.log(new Date - t1, 'new Date - t1') // !!!!!!!!!!diff is 3000+, should be 20+
  }, 20)
}, 20)

timediff should be 20+ms, but it would equal to the while block time.

@alsotang
Copy link
Author

In chrome 52.0.2743.116, the result is right.

@mscdex mscdex added the timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. label Aug 31, 2016
@medns
Copy link
Contributor

medns commented Aug 31, 2016

i review timers.js@v4.5.0 code, found the following code can be cause this problem.

if (diff < msecs) {
    list.start(msecs - diff, 0);
    debug('%d list wait because diff is %d', msecs, diff);
    return;
}

change to

if (diff < msecs) {
  if (diff >= 0) {
    list.start(msecs - diff, 0);
    debug('%d list wait because diff is %d', msecs, diff);
   } else {
    list.start(msecs, 0);
  }
  return;
}

can alleviate this issue

but in master version change the timeRemaining calc solve this issue

@alsotang
Copy link
Author

@alsotang
Copy link
Author

seems v6.5.0 solved this issue, should I close this?

@benjamingr
Copy link
Member

@alsotang can you please test on latest 5.x?

@Fishrock123
Copy link
Contributor

This was fixed by 5aac4c4 which landed in v6.x here: 49a6ea1

The v5.x branch is now end-of-life and will not receive it.

As noted in #3063 (comment), this fix is not on v4.x at the current time, but should probably land at some point.

@Fishrock123 Fishrock123 added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Aug 31, 2016
@alsotang
Copy link
Author

alsotang commented Sep 1, 2016

ok, I start use v6.5.0 right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
Projects
None yet
Development

No branches or pull requests

5 participants