Skip to content

Commit

Permalink
timers: fix handling of cleared immediates
Browse files Browse the repository at this point in the history
If current immediate has no callback, move on to the next one in
the queue.

Fixes: #9756
PR-URL: #9759
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
hassy authored and Fishrock123 committed Dec 14, 2016
1 parent 75ac109 commit 9f6f0f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,10 @@ function processImmediate() {
while (immediate) {
domain = immediate.domain;

if (!immediate._onImmediate)
if (!immediate._onImmediate) {
immediate = immediate._idleNext;
continue;
}

if (domain)
domain.enter();
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-timers-regress-GH-9765.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common');

// This test ensures that if an Immediate callback clears subsequent
// immediates we don't get stuck in an infinite loop.
//
// If the process does get stuck, it will be timed out by the test
// runner.
//
// Ref: https://github.com/nodejs/node/issues/9756

setImmediate(common.mustCall(function() {
clearImmediate(i2);
clearImmediate(i3);
}));

const i2 = setImmediate(function() {
common.fail('immediate callback should not have fired');
});

const i3 = setImmediate(function() {
common.fail('immediate callback should not have fired');
});

0 comments on commit 9f6f0f7

Please sign in to comment.