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

lib: introduce constant MAX_TICKS #11199

Closed
wants to merge 4 commits into from
Closed
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
10 changes: 8 additions & 2 deletions lib/internal/process/next_tick.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

// This value is used to prevent the nextTickQueue from becoming too
// large and cause the process to run out of memory. When this value
// is reached the nextTimeQueue array will be shortend (see tickDone
// for details).
const kMaxCallbacksUntilQueueIsShortened = 1e4;

exports.setup = setupNextTick;

function setupNextTick() {
Expand Down Expand Up @@ -96,7 +102,7 @@ function setupNextTick() {
// callback invocation with small numbers of arguments to avoid the
// performance hit associated with using `fn.apply()`
_combinedTickCallback(args, callback);
if (1e4 < tickInfo[kIndex])
if (kMaxCallbacksUntilQueueIsShortened < tickInfo[kIndex])
tickDone();
}
tickDone();
Expand All @@ -120,7 +126,7 @@ function setupNextTick() {
// callback invocation with small numbers of arguments to avoid the
// performance hit associated with using `fn.apply()`
_combinedTickCallback(args, callback);
if (1e4 < tickInfo[kIndex])
if (kMaxCallbacksUntilQueueIsShortened < tickInfo[kIndex])
tickDone();
if (domain)
domain.exit();
Expand Down