{"action":"created","issue":{"url":"https://api.github.com/repos/libuv/libuv/issues/1068","repository_url":"https://api.github.com/repos/libuv/libuv","labels_url":"https://api.github.com/repos/libuv/libuv/issues/1068/labels{/name}","comments_url":"https://api.github.com/repos/libuv/libuv/issues/1068/comments","events_url":"https://api.github.com/repos/libuv/libuv/issues/1068/events","html_url":"https://github.com/libuv/libuv/issues/1068","id":178930039,"number":1068,"title":"Linux: uv_timer_start seems to depend on last known time point","user":{"login":"alexhultman","id":3397140,"avatar_url":"https://avatars.githubusercontent.com/u/3397140?v=3","gravatar_id":"","url":"https://api.github.com/users/alexhultman","html_url":"https://github.com/alexhultman","followers_url":"https://api.github.com/users/alexhultman/followers","following_url":"https://api.github.com/users/alexhultman/following{/other_user}","gists_url":"https://api.github.com/users/alexhultman/gists{/gist_id}","starred_url":"https://api.github.com/users/alexhultman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexhultman/subscriptions","organizations_url":"https://api.github.com/users/alexhultman/orgs","repos_url":"https://api.github.com/users/alexhultman/repos","events_url":"https://api.github.com/users/alexhultman/events{/privacy}","received_events_url":"https://api.github.com/users/alexhultman/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-23T17:20:53Z","updated_at":"2016-09-23T18:15:23Z","closed_at":"2016-09-23T18:15:23Z","body":"I have found this strange behavior with timers in libuv:\r\n\r\n```c++\r\n#include <iostream>\r\n#include <chrono>\r\nusing namespace std;\r\n\r\n#include <uv.h>\r\n#include <unistd.h>\r\n\r\nstd::chrono::time_point<std::chrono::high_resolution_clock> start;\r\n\r\nint main()\r\n{\r\n    uv_loop_t *loop = uv_default_loop();\r\n\r\n    // trigger bug: block here!\r\n    sleep(5);\r\n\r\n    uv_timer_t timer;\r\n    uv_timer_init(loop, &timer);\r\n    start = std::chrono::high_resolution_clock::now();\r\n    uv_timer_start(&timer, [](uv_timer_t *timer) {\r\n        std::cout << \"Timer timed out now: \" << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start).count() << \" ms after call to uv_timer_start\" << std::endl;\r\n    }, 5000, 0);\r\n\r\n    uv_run(loop, UV_RUN_DEFAULT);\r\n}\r\n```\r\n\r\nThe timer callback is called 0ms after call to uv_timer_start, but if I remove the sleep it triggers 5 seconds after call to uv_timer_start. It seems the time point is not updated when calling uv_timer_start. I can \"fix\" this by running the loop before calling uv_timer_start.\r\n\r\nI'm using this Fedora package: libuv-devel-1:1.7.5-2.fc24.x86_64"},"comment":{"url":"https://api.github.com/repos/libuv/libuv/issues/comments/249264636","html_url":"https://github.com/libuv/libuv/issues/1068#issuecomment-249264636","issue_url":"https://api.github.com/repos/libuv/libuv/issues/1068","id":249264636,"user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"created_at":"2016-09-23T18:15:23Z","updated_at":"2016-09-23T18:15:23Z","body":"Call `uv_update_time(loop)` in scenarios like that.  Updating libuv's idea of \"now\" can be expensive so it postpones that until it must (mostly around polling for events.)"}}
{"actor":{"display_login":"bnoordhuis"}}