Skip to content

Commit f664613

Browse files
hassyMylesBorins
authored andcommitted
timers: fix handling of cleared immediates
If current immediate has no callback, move on to the next one in the queue. Fixes: #9756 PR-URL: #9759 Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent b9361ca commit f664613

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/timers.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,10 @@ function processImmediate() {
580580
while (immediate) {
581581
domain = immediate.domain;
582582

583-
if (!immediate._onImmediate)
583+
if (!immediate._onImmediate) {
584+
immediate = immediate._idleNext;
584585
continue;
586+
}
585587

586588
if (domain)
587589
domain.enter();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// This test ensures that if an Immediate callback clears subsequent
5+
// immediates we don't get stuck in an infinite loop.
6+
//
7+
// If the process does get stuck, it will be timed out by the test
8+
// runner.
9+
//
10+
// Ref: https://github.com/nodejs/node/issues/9756
11+
12+
setImmediate(common.mustCall(function() {
13+
clearImmediate(i2);
14+
clearImmediate(i3);
15+
}));
16+
17+
const i2 = setImmediate(function() {
18+
common.fail('immediate callback should not have fired');
19+
});
20+
21+
const i3 = setImmediate(function() {
22+
common.fail('immediate callback should not have fired');
23+
});

0 commit comments

Comments
 (0)