diagnostics_channel: replace using with try-finally#64251
diagnostics_channel: replace using with try-finally#64251ayush23chaudhary wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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
usingstatements with explicittry...finallyblocks that invoke[SymbolDispose](). - Updated scope handling in
ActiveChannel,BoundedChannel, andTracingChannelpaths to ensure disposal occurs reliably without relying on flagged syntax.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| triggerUncaughtException(err, false); | ||
| }); | ||
| continue; | ||
| const stack = new DisposableStack(); |
There was a problem hiding this comment.
DisposableStack is also a flagged global.
There was a problem hiding this comment.
@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.
| } finally { | ||
| if (this.#stack === undefined) { | ||
| for (let i = stack.length - 1; i >= 0; i--) { | ||
| stack[i][SymbolDispose](); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
#stack is not disposed by the constructor. This code should be removed, and the try ... finally block in the constructor is not needed.
| triggerUncaughtException(err, false); | ||
| }); | ||
| continue; | ||
| const stack = []; |
There was a problem hiding this comment.
| const stack = []; | |
| // TODO: use native DisposableStack once supported in core | |
| const stack = []; |
| for (let i = this.#stack.length - 1; i >= 0; i--) { | ||
| this.#stack[i][SymbolDispose](); | ||
| } | ||
| this.#stack = undefined; |
There was a problem hiding this comment.
| for (let i = this.#stack.length - 1; i >= 0; i--) { | |
| this.#stack[i][SymbolDispose](); | |
| } | |
| this.#stack = undefined; | |
| const stack = this.#stack; | |
| this.#stack = undefined; | |
| for (let i = stack.length - 1; i >= 0; i--) { | |
| stack[i][SymbolDispose](); | |
| } |
Matches the order of operations of DisposableStack.prototype.dispose(), in case anything touches the stack during disposal.
There was a problem hiding this comment.
Can any of the store disposers ever throw? If so, we need error handling here as well.
Fixes: #64230
Description
This PR replaces instances of the experimental
usingsyntax withtry...finallyblocks insidelib/diagnostics_channel.js.Since Explicit Resource Management is still a flagged feature in V8, encountering
usingin core causes a segfault when running Node with the--no-js-explicit-resource-managementflag. This refactor maintains the exact same resource cleanup semantics by manually calling[SymbolDispose]()in afinallyblock, avoiding the flagged syntax entirely.Example of Refactor
Before:
After