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 #2788

Closed
wants to merge 1 commit into from
Closed
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 @@ -59,14 +59,17 @@ function insert(item, msecs) {
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 nodejs/node-v0.x-archive issue #25831.
list.start(msecs, 0);

L.append(list, item);
assert(!L.isEmpty(list)); // list is not empty
Expand Down
36 changes: 36 additions & 0 deletions test/simple/test-timers-active-handles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var cp = require('child_process');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use strict should be the first line.

var assert = require('assert');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use const wherever you assign the value once and never reassign anything to the same.


// build deasync
cp.spawn(
process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp', ['rebuild'], {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require common at the top and use common.isWindows

stdio: 'inherit',
cwd: __dirname + '/test-timers-active-handles'
})
.on('exit', function (err) {
if (err) {
if (err === 127) {
console.error(
'node-gyp not found! Please upgrade your install of npm!'
);
} else {
console.error('Build failed');
}
return process.exit(err);
}
test();
});

function test() {
var uvRunOnce = require('./test-timers-active-handles/build/Release/deasync');
setTimeout(function () {
var res;
setTimeout(function () {
res = true;
}, 2);
while (!res) {
uvRunOnce.run();
}
assert.equal(res, true);
}, 2);
}
8 changes: 8 additions & 0 deletions test/simple/test-timers-active-handles/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"targets": [{
"target_name": "deasync",
"sources": [
"deasync.cc"
]
}]
}
17 changes: 17 additions & 0 deletions test/simple/test-timers-active-handles/deasync.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 = Isolate::GetCurrent();
HandleScope scope(isolate);
uv_run(uv_default_loop(), UV_RUN_ONCE);
args.GetReturnValue().Set(Undefined(isolate));
}

void init(Handle<Object> exports) {
NODE_SET_METHOD(exports, "run", Method);
}

NODE_MODULE(deasync, init)