Skip to content

diagnostics_channel: replace using with try-finally#64251

Open
ayush23chaudhary wants to merge 2 commits into
nodejs:mainfrom
ayush23chaudhary:fix-erm-diagnostics
Open

diagnostics_channel: replace using with try-finally#64251
ayush23chaudhary wants to merge 2 commits into
nodejs:mainfrom
ayush23chaudhary:fix-erm-diagnostics

Conversation

@ayush23chaudhary

Copy link
Copy Markdown

Fixes: #64230

Description

This PR replaces instances of the experimental using syntax with try...finally blocks inside lib/diagnostics_channel.js.

Since Explicit Resource Management is still a flagged feature in V8, encountering using in core causes a segfault when running Node with the --no-js-explicit-resource-management flag. This refactor maintains the exact same resource cleanup semantics by manually calling [SymbolDispose]() in a finally block, avoiding the flagged syntax entirely.

Example of Refactor

Before:

using scope = this.withStoreScope(data);
return ReflectApply(fn, thisArg, args);

After

const scope = this.withStoreScope(data);
try {
  return ReflectApply(fn, thisArg, args);
} finally {
  scope[SymbolDispose]();
}

Copilot AI review requested due to automatic review settings July 2, 2026 04:13
@nodejs-github-bot nodejs-github-bot added diagnostics_channel Issues and PRs related to diagnostics channel needs-ci PRs that need a full CI run. labels Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the experimental using syntax from lib/diagnostics_channel.js, replacing it with equivalent try...finally disposal to avoid crashes when Node is run with --no-js-explicit-resource-management.

Changes:

  • Replaced using statements with explicit try...finally blocks that invoke [SymbolDispose]().
  • Updated scope handling in ActiveChannel, BoundedChannel, and TracingChannel paths to ensure disposal occurs reliably without relying on flagged syntax.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/diagnostics_channel.js
Comment thread lib/diagnostics_channel.js
Comment thread lib/diagnostics_channel.js
Comment thread lib/diagnostics_channel.js Outdated
triggerUncaughtException(err, false);
});
continue;
const stack = new DisposableStack();

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.

DisposableStack is also a flagged global.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@Renegade334, I did not realize DisposableStack was part of the same flagged feature. I've replaced it with a standard array that manually iterates in reverse during disposal. Just pushed the update.

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

Labels

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.

Segfaults with [await] using within node core

4 participants