Skip to content
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 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

L.append(list, item);
assert(!L.isEmpty(list)); // list is not empty
Expand Down
17 changes: 17 additions & 0 deletions test/addons/timers-active-handles/binding.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <node.h>
#include <uv.h>

using namespace v8;

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)
8 changes: 8 additions & 0 deletions test/addons/timers-active-handles/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ]
}
]
}
13 changes: 13 additions & 0 deletions test/addons/timers-active-handles/test.js
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);