mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
9724047268
Commit 934bfe23a1
had introduced a
regression where node would crash trying to access a null unref timer if
a given unref timer's callback would remove other unref timers set to
fire in the future.
More generally, it makes the unrefTimeout function more solid by not
mutating the unrefList while traversing it.
Fixes: https://github.com/joyent/node/issues/8897
Conflicts:
lib/timers.js
Fixes: https://github.com/nodejs/node-convergence-archive/issues/23
Ref: https://github.com/nodejs/node/issues/268
PR-URL: https://github.com/nodejs/node/pull/2540
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
42 lines
956 B
JavaScript
42 lines
956 B
JavaScript
'use strict';
|
|
|
|
/*
|
|
* The goal of this test is to make sure that, after the regression introduced
|
|
* by 934bfe23a16556d05bfb1844ef4d53e8c9887c3d, the fix preserves the following
|
|
* behavior of unref timers: if two timers are scheduled to fire at the same
|
|
* time, if one unenrolls the other one in its _onTimeout callback, the other
|
|
* one will *not* fire.
|
|
*
|
|
* This behavior is a private implementation detail and should not be
|
|
* considered public interface.
|
|
*/
|
|
const common = require('../common');
|
|
const timers = require('timers');
|
|
const assert = require('assert');
|
|
|
|
var nbTimersFired = 0;
|
|
|
|
const foo = {
|
|
_onTimeout: function() {
|
|
++nbTimersFired;
|
|
timers.unenroll(bar);
|
|
}
|
|
};
|
|
|
|
const bar = {
|
|
_onTimeout: function() {
|
|
++nbTimersFired;
|
|
timers.unenroll(foo);
|
|
}
|
|
};
|
|
|
|
timers.enroll(bar, 1);
|
|
timers._unrefActive(bar);
|
|
|
|
timers.enroll(foo, 1);
|
|
timers._unrefActive(foo);
|
|
|
|
setTimeout(function() {
|
|
assert.notEqual(nbTimersFired, 2);
|
|
}, 20);
|