Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timers: prevent infinite loop when subsequent immediates are cleared #9759

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});