Skip to content

setTimeout bug. There is example #8354

Description

@alsotang
  • 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.

Activity

  1. alsotang commented on Aug 31, 2016

    @alsotang
    Author

    In chrome 52.0.2743.116, the result is right.

  2. added
    timersIssues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().
    on Aug 31, 2016
  3. medns commented on Aug 31, 2016

    @medns
    Contributor

    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

  4. alsotang commented on Aug 31, 2016

    @alsotang
    Author

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

  5. benjamingr commented on Aug 31, 2016

    @benjamingr
    Member

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

  6. Fishrock123 commented on Aug 31, 2016

    @Fishrock123
    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.

  7. added
    duplicateIssues and PRs that are duplicates of other issues or PRs.
    on Aug 31, 2016
  8. alsotang commented on Sep 1, 2016

    @alsotang
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateIssues and PRs that are duplicates of other issues or PRs.timersIssues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions