Repository navigation
setTimeout delayed when sleeping on Windows #6763
Description
Activity
- addedtimersIssues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().Issues and PRs related to timers, setImmediate(), setInterval(), and setTimeout().windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
on May 14, 2016 Libuv on Linux uses CLOCK_BOOTTIME when available (kernel >= 2.6.39). Windows doesn't have an equivalent with good enough precision, AFAIK.
Doesn't libuv on Linux simply use the timeout parameter of epoll_wait, just like it does on Windows with IOCP?
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.
Anyway, apparently
GetQueuedCompletionStatusdoesn'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
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.
@nodejs/collaborators @nodejs/platform-windows if anyone could try to reproduce this and post their results that would be great.
- addedlibuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.
on May 17, 2016 I can reproduce this issue on my desktop and laptop; both running Windows 10 (Pro & Enterprise), on v6.1.0.
Reacted by Nikolai VavilovPinging @orangemocha
<@saghul> maybe @ orangemocha, maybe he can ask someone on the Windows team at MicrosoftI 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.
@orangemocha have you found out anything?
I haven't investigated it yet, sorry. Bumping it.
- added a commit that references this issue
on Aug 1, 2016 Reopening since this is still an issue in node.js until libuv is updated.
- added a commit that references this issue
on Aug 18, 2016 - added a commit that references this issue
on Oct 26, 2016 - added a commit that references this issue
on Nov 3, 2016 - added 2 commits that reference this issue
on May 16, 2017 - added a commit that references this issue
on Jul 19, 2017
Testcase:
When running it normally, the result is as expected:
However, if you do the following:
The timeout fires not after the remaining 10 seconds, but after ~20 seconds:
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.