mirror of https://github.com/nodejs/node.git
Fixed: clearTimeouts calling multiple times
When clearTimeouts was called on a timer multiple times, it would break the doubly-linked list along with future timeouts. This patch fixes that.pull/22966/head
parent
22cf5a24db
commit
645c3b3713
|
@ -43,6 +43,7 @@ function shift (list) {
|
|||
function remove (item) {
|
||||
item._idleNext._idlePrev = item._idlePrev;
|
||||
item._idlePrev._idleNext = item._idleNext;
|
||||
item._idleNext = null;
|
||||
}
|
||||
|
||||
|
||||
|
@ -111,8 +112,7 @@ function insert (item, msecs) {
|
|||
|
||||
var unenroll = exports.unenroll = function (item) {
|
||||
if (item._idleNext) {
|
||||
item._idleNext._idlePrev = item._idlePrev;
|
||||
item._idlePrev._idleNext = item._idleNext;
|
||||
remove(item);
|
||||
|
||||
var list = lists[item._idleTimeout];
|
||||
// if empty then stop the watcher
|
||||
|
|
|
@ -84,8 +84,26 @@ interval4 = setInterval(function () {
|
|||
if (++count4 > 10) clearInterval(interval4);
|
||||
}, 0);
|
||||
|
||||
|
||||
// we should be able to clearTimeout multiple times without breakage.
|
||||
var expectedTimeouts = 3;
|
||||
|
||||
function t () {
|
||||
expectedTimeouts--;
|
||||
}
|
||||
|
||||
w = setTimeout(t, 200),
|
||||
x = setTimeout(t, 200),
|
||||
y = setTimeout(t, 200);
|
||||
|
||||
clearTimeout(y),
|
||||
z = setTimeout(t, 200);
|
||||
clearTimeout(y);
|
||||
|
||||
|
||||
process.addListener("exit", function () {
|
||||
assert.equal(true, setTimeout_called);
|
||||
assert.equal(3, interval_count);
|
||||
assert.equal(11, count4);
|
||||
assert.equal(0, expectedTimeouts, "clearTimeout cleared too many timeouts");
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue