Skip to content

diagnostics_channel: grow native channel storage#64497

Open
Qard wants to merge 1 commit into
nodejs:mainfrom
Qard:agent/grow-native-diagnostics-channel-storage
Open

diagnostics_channel: grow native channel storage#64497
Qard wants to merge 1 commit into
nodejs:mainfrom
Qard:agent/grow-native-diagnostics-channel-storage

Conversation

@Qard

@Qard Qard commented Jul 14, 2026

Copy link
Copy Markdown
Member

Every string-named diagnostics channel currently consumes an entry in a fixed
native subscriber array, so creating more than 1,024 channels terminates the
process at a native CHECK.

Only channels used by native publishers now receive native slots, and the
subscriber buffer grows when it fills. This removes the arbitrary crash while
preserving subscriber tracking and snapshot behavior.

cc @nodejs/diagnostics

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. diagnostics_channel Issues and PRs related to diagnostics channel needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. labels Jul 14, 2026
@Qard Qard self-assigned this Jul 14, 2026
@Qard Qard added request-ci Add this label to start a Jenkins CI on a PR. and removed process Issues and PRs related to the process subsystem. labels Jul 14, 2026
@Qard
Qard marked this pull request as ready for review July 14, 2026 12:35
@Qard
Qard marked this pull request as draft July 14, 2026 12:36
@Qard
Qard marked this pull request as ready for review July 14, 2026 12:36
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.24%. Comparing base (7a11a9b) to head (3a6cf52).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
lib/diagnostics_channel.js 53.84% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #64497   +/-   ##
=======================================
  Coverage   90.24%   90.24%           
=======================================
  Files         739      739           
  Lines      241669   241682   +13     
  Branches    45543    45554   +11     
=======================================
+ Hits       218087   218113   +26     
+ Misses      15150    15112   -38     
- Partials     8432     8457   +25     
Files with missing lines Coverage Δ
lib/internal/process/pre_execution.js 98.07% <100.00%> (+0.13%) ⬆️
src/node_diagnostics_channel.cc 83.51% <100.00%> (+1.64%) ⬆️
src/node_diagnostics_channel.h 57.14% <ø> (ø)
lib/diagnostics_channel.js 97.57% <53.84%> (-0.59%) ⬇️

... and 38 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Every string-named JavaScript channel consumed an entry in the fixed
native subscriber array. Creating more than 1,024 channels triggered a
CHECK and terminated the process.

Allocate slots only for native publishers and grow the aliased buffer
when it fills. Refresh the JavaScript view after resizing and preserve
the capacity in snapshots.

Signed-off-by: Stephen Belanger <admin@stephenbelanger.com>
@Qard
Qard force-pushed the agent/grow-native-diagnostics-channel-storage branch from af80173 to 3a6cf52 Compare July 15, 2026 04:48
@Qard Qard added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jul 15, 2026
@Qard Qard added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jul 16, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 16, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@bjohansebas bjohansebas added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 16, 2026
Comment thread test/parallel/test-permission-diagnostics-channel.js
this.name = name;
if (typeof name === 'string') {
this._index = dc_binding.getOrCreateChannelIndex(name);
this._index = undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this only done in case typeof name === 'string'?
I think the if should be removed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symbol channels aren't supported/used on the native side, so we skip them here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if I get this right we either set explict undefined or implict by not setting it at all.
What is the difference to never add it or always set it to undefined?

const { triggerUncaughtException } = internalBinding('errors');

const dc_binding = internalBinding('diagnostics_channel');
const { subscribers: subscriberCounts } = dc_binding;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this right the growing of subscribers disallows destruction here as we would end up in a dangling reference.
Do we have any tools in hand to detect such subtle import issues?

const dc_binding = internalBinding('diagnostics_channel');
dc_binding.linkNativeChannel((name) => dc.channel(name));
dc_binding.linkNativeChannel((name, index) => {
const channel = dc.channel(name);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is no simple way to avoid code duplication with lib/diagnostics_channel.js right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. diagnostics_channel Issues and PRs related to diagnostics channel needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants