Skip to content

src: convert context_frame field in AsyncWrap to internal field#62103

Open
addaleax wants to merge 3 commits intonodejs:mainfrom
addaleax:async-wrap-async-context-frame-gc
Open

src: convert context_frame field in AsyncWrap to internal field#62103
addaleax wants to merge 3 commits intonodejs:mainfrom
addaleax:async-wrap-async-context-frame-gc

Conversation

@addaleax
Copy link
Member

@addaleax addaleax commented Mar 4, 2026

Refs: #61995 (comment)

src: make AsyncWrap subclass internal field counts explicit

This helps ensure that we already set the correct number of
internal fields when creating objects, even if the number of
internal fields of e.g. AsyncWrap changes over time.

src: convert context_frame field in AsyncWrap to internal field

Using an internal field instead of a v8::Global<> removes
an unnecessary memory leak footgun.

This includes a test that demonstrates the issue, albeit
using internal APIs.

It's worth noting that if this PR is not accepted, we'd still
be missing memory tracking for the context_frame_ field,
and we'd need to add it through our memory tracking API.

src: expose async context frame debugging helper to JS

This was invaluable for debugging the previous change,
so I'm suggesting we add it regardless of it being a
debugging-only API.

addaleax added 3 commits March 4, 2026 16:55
This helps ensure that we already set the correct number of
internal fields when creating objects, even if the number of
internal fields of e.g. AsyncWrap changes over time.
Using an internal field instead of a `v8::Global<>` removes
an unnecessary memory leak footgun.

This includes a test that demonstrates the issue, albeit
using internal APIs.

It's worth noting that if this PR is not accepted, we'd still
be missing memory tracking for the `context_frame_` field,
and we'd need to add it through our memory tracking API.
This was invaluable for debugging the previous change,
so I'm suggesting we add it regardless of it being a
debugging-only API.
@addaleax addaleax requested review from Flarna and Qard March 4, 2026 16:22
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/http2
  • @nodejs/net
  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Mar 4, 2026
@addaleax addaleax added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. labels Mar 4, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 4, 2026
@nodejs-github-bot

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 92.98246% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.64%. Comparing base (afc30b7) to head (8a82488).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/async_wrap.cc 71.42% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #62103   +/-   ##
=======================================
  Coverage   89.64%   89.64%           
=======================================
  Files         676      676           
  Lines      206326   206343   +17     
  Branches    39528    39532    +4     
=======================================
+ Hits       184960   184985   +25     
- Misses      13476    13483    +7     
+ Partials     7890     7875   -15     
Files with missing lines Coverage Δ
src/async_wrap-inl.h 95.12% <100.00%> (+2.81%) ⬆️
src/base_object.cc 84.46% <100.00%> (+0.15%) ⬆️
src/base_object.h 100.00% <ø> (ø)
src/cares_wrap.cc 61.64% <100.00%> (-0.09%) ⬇️
src/crypto/crypto_keys.cc 73.75% <ø> (ø)
src/crypto/crypto_sig.cc 70.34% <100.00%> (ø)
src/crypto/crypto_tls.cc 77.85% <100.00%> (ø)
src/crypto/crypto_tls.h 86.66% <ø> (ø)
src/crypto/crypto_util.h 74.79% <ø> (ø)
src/crypto/crypto_x509.cc 72.44% <ø> (ø)
... and 20 more

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

@nodejs-github-bot
Copy link
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/71571/

@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. async_local_storage AsyncLocalStorage labels Mar 4, 2026
@addaleax addaleax added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

async_local_storage AsyncLocalStorage 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++. commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants