-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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 delayed when sleeping on Windows #6763
Comments
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 #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. |
I can reproduce this issue on my desktop and laptop; both running Windows 10 (Pro & Enterprise), on v6.1.0. |
Pinging @orangemocha
|
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. |
@orangemocha have you found out anything? |
I haven't investigated it yet, sorry. Bumping it. |
When Windows resumes after sleep GetQueuedCompletionStatus timeout is not updated. This commit adds a method for signaling all loops to wake up and update their timers. Fixes: nodejs/node#6763
Reopening since this is still an issue in node.js until libuv is updated. |
When Windows resumes after sleep GetQueuedCompletionStatus timeout is not updated. This commit adds a method for signaling all loops to wake up and update their timers. Fixes: nodejs/node#6763 PR-URL: libuv#962 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Fixes: nodejs#4351 Fixes: nodejs#6763 Refs: nodejs#8280 PR-URL: nodejs#9267 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Fixes: nodejs/node#4351 Fixes: nodejs/node#6763 Refs: nodejs/node#8280 PR-URL: nodejs/node#9267 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
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.
The text was updated successfully, but these errors were encountered: