Skip to content

async_hooks: add using scopes to AsyncLocalStorage#61674

Merged
nodejs-github-bot merged 2 commits intonodejs:mainfrom
Qard:als-run-scope
Mar 28, 2026
Merged

async_hooks: add using scopes to AsyncLocalStorage#61674
nodejs-github-bot merged 2 commits intonodejs:mainfrom
Qard:als-run-scope

Conversation

@Qard
Copy link
Copy Markdown
Member

@Qard Qard commented Feb 4, 2026

Adds support for using scope = storage.withScope(data) to do the equivalent of a storage.run(data, fn) with using syntax. This enables avoiding unnecessary closures.

cc @nodejs/diagnostics

@Qard Qard self-assigned this Feb 4, 2026
@Qard Qard added async_hooks Issues and PRs related to the async hooks subsystem. async_local_storage AsyncLocalStorage labels Feb 4, 2026
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Feb 4, 2026
@Qard Qard force-pushed the als-run-scope branch 2 times, most recently from af2ad3e to d8e83aa Compare February 4, 2026 11:50
@Flarna
Copy link
Copy Markdown
Member

Flarna commented Feb 4, 2026

I guess this replaces #58104 right?

@Qard
Copy link
Copy Markdown
Member Author

Qard commented Feb 4, 2026

Ah, yes. Forgot that one existed. 😅

@Qard Qard force-pushed the als-run-scope branch 2 times, most recently from 8b875c4 to 09cb6ad Compare February 4, 2026 14:14
@Qard Qard added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 4, 2026
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Feb 4, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 4, 2026

Failed to start CI
   ⚠  No approving reviews found
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/21678728231

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.68%. Comparing base (06a8240) to head (b055801).
⚠️ Report is 63 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #61674   +/-   ##
=======================================
  Coverage   89.68%   89.68%           
=======================================
  Files         676      677    +1     
  Lines      206578   206621   +43     
  Branches    39555    39567   +12     
=======================================
+ Hits       185267   185308   +41     
- Misses      13446    13447    +1     
- Partials     7865     7866    +1     
Files with missing lines Coverage Δ
...nternal/async_local_storage/async_context_frame.js 100.00% <100.00%> (ø)
lib/internal/async_local_storage/async_hooks.js 98.03% <100.00%> (+0.08%) ⬆️
lib/internal/async_local_storage/run_scope.js 100.00% <100.00%> (ø)

... and 28 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.

@addaleax addaleax added semver-minor PRs that contain new features and should be released in the next minor version. request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels Feb 6, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 6, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@Flarna Flarna added dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. labels Feb 6, 2026
Adds support for using scope = storage.withScope(data) to do
the equivalent of a storage.run(data, fn) with using syntax.
This enables avoiding unnecessary closures.
@Qard
Copy link
Copy Markdown
Member Author

Qard commented Mar 22, 2026

What are folks' opinions on public versus internal for this? The primary motivation for this is just to eliminate all the closure nesting in channel.runStores(...). We could opt for landing this undocumented, as an internal-only tool, if we're concerned about the possible safety issues of using ERM wrong.

@Qard Qard added request-ci Add this label to start a Jenkins CI on a PR. commit-queue Add this label to land a pull request using GitHub Actions. labels Mar 22, 2026
@panva panva removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 25, 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 Mar 25, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 26, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@Flarna
Copy link
Copy Markdown
Member

Flarna commented Mar 26, 2026

I see no benefit with internal only. enterWith is exposed already which allows to leak context already now.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@Qard Qard added commit-queue Add this label to land a pull request using GitHub Actions. and removed needs-ci PRs that need a full CI run. labels Mar 28, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 28, 2026
@nodejs-github-bot nodejs-github-bot merged commit 5b6091c into nodejs:main Mar 28, 2026
78 of 81 checks passed
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Landed in 5b6091c

@Qard Qard deleted the als-run-scope branch March 28, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

async_hooks Issues and PRs related to the async hooks subsystem. async_local_storage AsyncLocalStorage dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants