-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
timer: call list.start regardless new or not #2830
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,14 +40,17 @@ exports.active = function(item) { | |
list = lists[msecs]; | ||
} else { | ||
list = new Timer(); | ||
list.start(msecs, 0); | ||
|
||
L.init(list); | ||
|
||
lists[msecs] = list; | ||
list.msecs = msecs; | ||
list[kOnTimeout] = listOnTimeout; | ||
} | ||
// Call start regardless whether list is new | ||
// or not to prevent incorrect active_handles | ||
// count. See https://github.com/nodejs/node-v0.x-archive/issues/25831. | ||
list.start(msecs, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the previous list start time was less than this list start time? I think it should check that, if I am following the logic correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @abbr ^ |
||
|
||
L.append(list, item); | ||
assert(!L.isEmpty(list)); // list is not empty | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <node.h> | ||
#include <uv.h> | ||
|
||
using namespace v8; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead we prefer |
||
|
||
void Method(const FunctionCallbackInfo<Value>& args) { | ||
Isolate* isolate = args.GetIsolate(); | ||
int hCnt = uv_default_loop()->active_handles; | ||
uv_run(uv_default_loop(), UV_RUN_ONCE); | ||
args.GetReturnValue().Set(Integer::New(isolate, hCnt)); | ||
} | ||
|
||
void init(Handle<Object> exports) { | ||
NODE_SET_METHOD(exports, "run", Method); | ||
} | ||
|
||
NODE_MODULE(deasync, init) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'sources': [ 'binding.cc' ] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
var uvRunOnce = require('./build/Release/binding'); | ||
setTimeout(function () { | ||
var res; | ||
setTimeout(function () { | ||
res = true; | ||
}, 2); | ||
while (!res && uvRunOnce.run()) { | ||
} | ||
assert.equal(res, true); | ||
}, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new logic is definitely not correct.
If you do this you are at very high risk (almost 100%) of delaying existing, running timers. Read my extensive comments in
node/lib/timers.js
Lines 68 to 78 in 7c9a691
Perhaps it would work correctly if you did the following:
If that worked, I would be willing to entertain changing the impl to that.
(Note: made comment on a different line so it would show at the bottom of the issue thread.)