GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — diagnostics_channel: replace using with try-finally by ayush23chaudhary · Pull Request #64251 · nodejs/node

diagnostics_channel: replace using with try-finally #64251

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.

Sign up for GitHub

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

Merged
nodejs-github-bot merged 4 commits into nodejs:main from ayush23chaudhary:fix-erm-diagnostics
Sep 19, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

diagnostics_channel: replace using with try-finally #64251

Changes from 3 commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
50b7999
diagnostics_channel: replace using with try-finally
ayush23chaudhary Jul 2, 2026
38c0c64
fixup! diagnostics_channel: replace using with try-finally
Renegade334 Aug 21, 2026
70dabe7
fixup! diagnostics_channel: replace using with try-finally
ayush23chaudhary Aug 24, 2026
26f975d
fixup! diagnostics_channel: replace using with try-finally
ayush23chaudhary Sep 4, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

88 changes: 63 additions & 25 deletions 88 lib/diagnostics_channel.js
Show comments Show annotations
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
} = primordials;

const {
aggregateTwoErrors,
codes: {
ERR_INVALID_ARG_TYPE,
},
Expand Down Expand Up @@ -84,12 +85,25 @@ function maybeMarkInactive(channel) {
}
}

function disposeStoreScopes(stack, error, hasError = false) {
for (let i = stack.length - 1; i >= 0; i--) {
try {
stack[i][SymbolDispose]();
} catch (err) {
error = hasError ? aggregateTwoErrors(err, error) : err;
hasError = true;
}
}

if (hasError) throw error;
}

class RunStoresScope {
#stack;

constructor(activeChannel, data) {
// eslint-disable-next-line no-restricted-globals
using stack = new DisposableStack();
// TODO: use native DisposableStack once supported in core
const stack = [];
Comment thread
Renegade334 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


// Enter stores using withScope
if (activeChannel._stores) {
Expand All @@ -109,19 +123,29 @@ class RunStoresScope {
}
}

stack.use(store.withScope(newContext));
try {
ArrayPrototypePush(stack, store.withScope(newContext));
} catch (err) {
disposeStoreScopes(stack, err, true);
}
}
}

// Publish data
activeChannel.publish(data);

// Transfer ownership of the stack
this.#stack = stack.move();
// TODO: Restore stack.move() when DisposableStack is restored in core to avoid broken behavior.
this.#stack = stack;
}

[SymbolDispose]() {
this.#stack[SymbolDispose]();
if (this.#stack !== undefined) {
const stack = this.#stack;
this.#stack = undefined;

disposeStoreScopes(stack);
}
}
}

Expand Down Expand Up @@ -197,9 +221,12 @@ class ActiveChannel {
}

runStores(data, fn, thisArg, ...args) {
// eslint-disable-next-line no-unused-vars
using scope = this.withStoreScope(data);
return ReflectApply(fn, thisArg, args);
const scope = this.withStoreScope(data);
try {
return ReflectApply(fn, thisArg, args);
} finally {
scope[SymbolDispose]();
}
}
}

Expand Down Expand Up @@ -396,9 +423,12 @@ class BoundedChannel {

run(context, fn, thisArg, ...args) {
context ??= {};
// eslint-disable-next-line no-unused-vars
using scope = this.withScope(context);
return ReflectApply(fn, thisArg, args);
const scope = this.withScope(context);
try {
return ReflectApply(fn, thisArg, args);
} finally {
scope[SymbolDispose]();
}
}
}

Expand Down Expand Up @@ -520,9 +550,8 @@ class TracingChannel {
}

const { error } = this;
const scope = this.#callWindow.withScope(context);

// eslint-disable-next-line no-unused-vars
using scope = this.#callWindow.withScope(context);
try {
const result = ReflectApply(fn, thisArg, args);
context.result = result;
Expand All @@ -531,6 +560,8 @@ class TracingChannel {
context.error = err;
error.publish(context);
throw err;
} finally {
scope[SymbolDispose]();
}
}

Expand All @@ -550,9 +581,9 @@ class TracingChannel {
context.error = err;
error.publish(context);
// Use continuation window for asyncStart/asyncEnd
// eslint-disable-next-line no-unused-vars
using scope = continuationWindow.withScope(context);
const scope = continuationWindow.withScope(context);
// TODO: Is there a way to have asyncEnd _after_ the continuation?
scope[SymbolDispose]();
}

function onRejectWithRethrow(err) {
Expand All @@ -563,14 +594,14 @@ class TracingChannel {
function onResolve(result) {
context.result = result;
// Use continuation window for asyncStart/asyncEnd
// eslint-disable-next-line no-unused-vars
using scope = continuationWindow.withScope(context);
const scope = continuationWindow.withScope(context);
// TODO: Is there a way to have asyncEnd _after_ the continuation?
scope[SymbolDispose]();
return result;
}

// eslint-disable-next-line no-unused-vars
using scope = this.#callWindow.withScope(context);
const scope = this.#callWindow.withScope(context);

try {
const result = ReflectApply(fn, thisArg, args);
// If the return value is not a thenable, return it directly with a warning.
Expand All @@ -595,6 +626,8 @@ class TracingChannel {
context.error = err;
error.publish(context);
throw err;
} finally {
scope[SymbolDispose]();
}
}

Expand All @@ -615,23 +648,28 @@ class TracingChannel {
}

// Use continuation window for asyncStart/asyncEnd around callback
// eslint-disable-next-line no-unused-vars
using scope = continuationWindow.withScope(context);
return ReflectApply(callback, this, arguments);
const scope = continuationWindow.withScope(context);
try {
return ReflectApply(callback, this, arguments);
} finally {
scope[SymbolDispose]();
}
}

const callback = ArrayPrototypeAt(args, position);
validateFunction(callback, 'callback');
ArrayPrototypeSplice(args, position, 1, wrappedCallback);

// eslint-disable-next-line no-unused-vars
using scope = this.#callWindow.withScope(context);
const scope = this.#callWindow.withScope(context);

try {
return ReflectApply(fn, thisArg, args);
} catch (err) {
context.error = err;
error.publish(context);
throw err;
} finally {
scope[SymbolDispose]();
}
}
}
Expand All @@ -651,4 +689,4 @@ module.exports = {
boundedChannel,
Channel,
BoundedChannel,
};
};
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.