镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

setTimeout delayed when sleeping on Windows #6763

Description

@seishun
  • Version: v6.1.0 and master
  • Platform: Windows 10 64-bit
  • Subsystem: timers

Testcase:

console.log(Date());
setTimeout(function() {
    console.log(Date());
}, 20000);

When running it normally, the result is as expected:

Sat May 14 2016 23:20:36 GMT+0300 (FLE Daylight Time)
Sat May 14 2016 23:20:56 GMT+0300 (FLE Daylight Time)

However, if you do the following:

  1. Start the script.
  2. Put the computer to sleep ASAP.
  3. Resume after 10 seconds.

The timeout fires not after the remaining 10 seconds, but after ~20 seconds:

Sat May 14 2016 23:22:14 GMT+0300 (FLE Daylight Time)
Sat May 14 2016 23:22:45 GMT+0300 (FLE Daylight Time)

I've asked on IRC and people say that this doesn't happen on Linux. That is, the callback is not delayed unless it would have occurred during sleep, in which case it's fired as soon as the computer wakes up.

Activity

  1. added
    timersIssues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().
    windowsIssues and PRs related to the Windows platform.
    on May 14, 2016
  2. bnoordhuis commented on May 15, 2016

    @bnoordhuis
    Member

    Libuv on Linux uses CLOCK_BOOTTIME when available (kernel >= 2.6.39). Windows doesn't have an equivalent with good enough precision, AFAIK.

  3. seishun commented on May 15, 2016

    @seishun
    ContributorAuthor

    Doesn't libuv on Linux simply use the timeout parameter of epoll_wait, just like it does on Windows with IOCP?

  4. bnoordhuis commented on May 15, 2016

    @bnoordhuis
    Member

    I take back what I said. I thought CLOCK_BOOTTIME was the clock source for timers but it's the clock source for uptime calculations only.

  5. seishun commented on May 15, 2016

    @seishun
    ContributorAuthor

    Anyway, apparently GetQueuedCompletionStatus doesn't advance the timeout while sleeping. Testcase:

    #include "Windows.h"
    #include <ctime>
    #include <iostream>
    #include <iomanip>
    
    int main()
    {
      auto whatever = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
      OVERLAPPED_ENTRY entries[10];
    
      auto t = std::time(nullptr);
      auto tm = *std::localtime(&t);
      std::cout << std::put_time(&tm, "%d-%m-%Y %H-%M-%S") << std::endl;
    
      ULONG bleh;
      GetQueuedCompletionStatusEx(whatever, entries, 10, &bleh, 20000, FALSE);
    
      // try sleeping here
    
      t = std::time(nullptr);
      tm = *std::localtime(&t);
      std::cout << std::put_time(&tm, "%d-%m-%Y %H-%M-%S") << std::endl;
    
    }

    I'm not sure if there is an alternative that works properly. Pinging @piscisaureus

  6. seishun commented on May 17, 2016

    @seishun
    ContributorAuthor

    Well what do you know. I cannot reproduce this on Windows 7. Either I've discovered an obscure bug in Windows 10, or there's something funky going on with my Windows 10 machine.

  7. seishun commented on May 17, 2016

    @seishun
    ContributorAuthor

    @nodejs/collaborators @nodejs/platform-windows if anyone could try to reproduce this and post their results that would be great.

  8. added
    libuvIssues and PRs related to the libuv dependency or the uv binding.
    on May 17, 2016
  9. iakat commented on May 18, 2016

    @iakat

    I can reproduce this issue on my desktop and laptop; both running Windows 10 (Pro & Enterprise), on v6.1.0.

  10. seishun commented on May 29, 2016

    @seishun
    ContributorAuthor

    Pinging @orangemocha

    <@saghul> maybe @ orangemocha, maybe he can ask someone on the Windows team at Microsoft

  11. orangemocha commented on May 30, 2016

    @orangemocha
    Contributor

    I don't know the answer from the top of my head, but I'll follow up on this one. Thank you for bringing it to my attention.

  12. seishun commented on Jul 5, 2016

    @seishun
    ContributorAuthor

    @orangemocha have you found out anything?

  13. orangemocha commented on Jul 6, 2016

    @orangemocha
    Contributor

    I haven't investigated it yet, sorry. Bumping it.

  14. added a commit that references this issue on Aug 1, 2016
  15. seishun commented on Aug 12, 2016

    @seishun
    ContributorAuthor

    Reopening since this is still an issue in node.js until libuv is updated.

  16. added a commit that references this issue on Oct 26, 2016
  17. added a commit that references this issue on Nov 3, 2016
  18. added a commit that references this issue on Jul 19, 2017
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

    libuvIssues and PRs related to the libuv dependency or the uv binding.timersIssues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions