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-only-one-fires.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-only-one-fires.js')
-rw-r--r-- | test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js b/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js new file mode 100644 index 0000000000..aead4a4e7d --- /dev/null +++ b/test/parallel/test-timers-unref-remove-other-unref-timers-only-one-fires.js @@ -0,0 +1,41 @@ +'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); |