Skip to content

Commit

Permalink
timer: call list.start regardless new or not
Browse files Browse the repository at this point in the history
Call start regardless whether list is new
or not to prevent incorrect active_handles
count.

Fixes nodejs/node-v0.x-archive#25831
  • Loading branch information
abbr committed Oct 13, 2015
1 parent bde32f8 commit 966b336
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
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);

0 comments on commit 966b336

Please sign in to comment.