Skip to content

Commit 8597b1b

Browse files
committed
timer: call list.start regardless new or not
Call start regardless whether list is new or not to prevent incorrect active_handles count. Fixes nodejs/node-v0.x-archive#25831.
1 parent 2860c53 commit 8597b1b

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

lib/timers.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,17 @@ function insert(item, msecs) {
5959
list = lists[msecs];
6060
} else {
6161
list = new Timer();
62-
list.start(msecs, 0);
6362

6463
L.init(list);
6564

6665
lists[msecs] = list;
6766
list.msecs = msecs;
6867
list[kOnTimeout] = listOnTimeout;
6968
}
69+
// Call start regardless whether list is new
70+
// or not to prevent incorrect active_handles
71+
// count. See nodejs/node-v0.x-archive issue #25831.
72+
list.start(msecs, 0);
7073

7174
L.append(list, item);
7275
assert(!L.isEmpty(list)); // list is not empty
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var cp = require('child_process');
2+
var assert = require('assert');
3+
4+
// build deasync
5+
cp.spawn(
6+
process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp', ['rebuild'], {
7+
stdio: 'inherit',
8+
cwd: __dirname + '/test-timers-active-handles'
9+
})
10+
.on('exit', function (err) {
11+
if (err) {
12+
if (err === 127) {
13+
console.error(
14+
'node-gyp not found! Please upgrade your install of npm!'
15+
);
16+
} else {
17+
console.error('Build failed');
18+
}
19+
return process.exit(err);
20+
}
21+
test();
22+
});
23+
24+
function test() {
25+
var uvRunOnce = require('./test-timers-active-handles/build/Release/deasync');
26+
setTimeout(function () {
27+
var res;
28+
setTimeout(function () {
29+
res = true;
30+
}, 2);
31+
while (!res) {
32+
uvRunOnce.run();
33+
}
34+
assert.equal(res, true);
35+
}, 2);
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"targets": [{
3+
"target_name": "deasync",
4+
"sources": [
5+
"deasync.cc"
6+
]
7+
}]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <node.h>
2+
#include <uv.h>
3+
4+
using namespace v8;
5+
6+
void Method(const FunctionCallbackInfo<Value>& args) {
7+
Isolate* isolate = Isolate::GetCurrent();
8+
HandleScope scope(isolate);
9+
uv_run(uv_default_loop(), UV_RUN_ONCE);
10+
args.GetReturnValue().Set(Undefined(isolate));
11+
}
12+
13+
void init(Handle<Object> exports) {
14+
NODE_SET_METHOD(exports, "run", Method);
15+
}
16+
17+
NODE_MODULE(deasync, init)

0 commit comments

Comments
 (0)