diff options
author | Julien Gilli <julien.gilli@joyent.com> | 2014-12-18 15:36:21 -0800 |
---|---|---|
committer | João Reis <reis@janeasystems.com> | 2015-09-02 08:14:25 -0400 |
commit | 9724047268afb96ba5435d98636ea745740fd12f (patch) | |
tree | 6ff3395f8d74560ed85f1e4dc1a2790c25ceaafd /test/parallel/test-timers-unref-remove-other-unref-timers.js | |
parent | e5bb66886bfa40818de7a96e982c5964eef9eb78 (diff) | |
download | android-node-v8-9724047268afb96ba5435d98636ea745740fd12f.tar.gz android-node-v8-9724047268afb96ba5435d98636ea745740fd12f.tar.bz2 android-node-v8-9724047268afb96ba5435d98636ea745740fd12f.zip |
timers: don't mutate unref list while iterating it
Commit 934bfe23a16556d05bfb1844ef4d53e8c9887c3d 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>
Diffstat (limited to 'test/parallel/test-timers-unref-remove-other-unref-timers.js')
-rw-r--r-- | test/parallel/test-timers-unref-remove-other-unref-timers.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/parallel/test-timers-unref-remove-other-unref-timers.js b/test/parallel/test-timers-unref-remove-other-unref-timers.js new file mode 100644 index 0000000000..f727d5f86f --- /dev/null +++ b/test/parallel/test-timers-unref-remove-other-unref-timers.js @@ -0,0 +1,33 @@ +'use strict'; + +/* + * This test is a regression test for joyent/node#8897. + * + * It tests some private implementation details that should not be + * considered public interface. + */ +const common = require('../common'); +const assert = require('assert'); +const timers = require('timers'); + +const foo = { + _onTimeout: assert.fail +}; + +const bar = { + _onTimeout: common.mustCall(function() { + timers.unenroll(foo); + }) +}; + +// We use timers with expiration times that are sufficiently apart to make +// sure that they're not fired at the same time on platforms where the timer +// resolution is a bit coarse (e.g Windows with a default resolution of ~15ms). +timers.enroll(bar, 1); +timers._unrefActive(bar); + +timers.enroll(foo, 50); +timers._unrefActive(foo); + +// Keep the process open. +setTimeout(function() {}, 100); |