Skip to content

fix(wall): hold the PCP holder in a Global, not a Persistent - #387

Merged
szegedi merged 1 commit into
mainfrom
szegedi/pcp-use-global
Aug 7, 2026
Merged

fix(wall): hold the PCP holder in a Global, not a Persistent#387
szegedi merged 1 commit into
mainfrom
szegedi/pcp-use-global

Conversation

@szegedi

@szegedi szegedi commented Aug 7, 2026

Copy link
Copy Markdown

Review follow-up on #385 (@nsavoire's two nits, both landed after merge).

Persistent -> Global

v8::Persistent has no destruction behaviour — the handle leaks unless every path clears it by hand. v8::Global releases it in its own destructor, and is what every other handle in this file already uses: ContextPtr, cpedKey_, wrapObjectTemplate_, jsArray_. The Persistent I introduced in #385 was the odd one out.

Nothing was actually leaking, since ~PersistentContextPtr always reset the handle explicitly — but relying on that is exactly the footgun the docs warn about. With Global the release becomes structural, so the explicit Reset() goes away with it.

Worth recording why the manual handle existed at all: before #261 removed instance reuse, PersistentContextPtr recycled itself through a freelist and needed ClearWeak/Reset to unregister and re-register the same object. With reuse gone, a handle lives exactly as long as its PCP, so there's nothing left for Persistent's manual semantics to buy.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Overall package size

Self size: 2.46 MB
Deduped: 3.16 MB
No deduping: 3.16 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | pprof-format | 2.3.0 | 503.97 kB | 503.97 kB | | source-map | 0.8.0 | 185.66 kB | 185.66 kB | | node-gyp-build | 4.8.4 | 13.86 kB | 13.86 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 7, 2026

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 4677a01 | Docs | Datadog PR Page | Give us feedback!

@szegedi szegedi added the semver-patch Bug or security fixes, mainly label Aug 7, 2026
Review follow-up on #385.

v8::Persistent has no destruction behaviour: the handle leaks unless every
path clears it by hand. v8::Global releases it in its own destructor, and
is what every other handle in this file already uses — ContextPtr,
cpedKey_, wrapObjectTemplate_, jsArray_. The Persistent introduced in #385
was the odd one out.

Nothing was leaking in practice, since ~PersistentContextPtr always reset
the handle explicitly, but relying on that is exactly the footgun the V8
docs warn about. Switching to Global makes the release structural, so the
explicit Reset goes away with it.

Historically the manual handle was justified: before #261 removed instance
reuse, PersistentContextPtr recycled itself through a freelist and needed
ClearWeak/Reset to unregister and re-register the same object. With reuse
gone a handle lives exactly as long as its PCP, so there is nothing left
for Persistent's manual semantics to buy.

Also correct the destructor comment. It claimed the reset was "a no-op
when we got here from WeakCallback itself", which is backwards: V8
requires a weak callback to reset the handle, so that path is precisely
where the release is load-bearing.

Verified on Node 20, 24 and 26 — the last is where AsyncContextFrame is on
by default and PCPs are actually created. 163 passing, ASAN exit 0 with no
leaks and no aborts on 20 and 24.
@szegedi
szegedi merged commit 9c00d10 into main Aug 7, 2026
123 of 128 checks passed
@szegedi
szegedi deleted the szegedi/pcp-use-global branch August 7, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-patch Bug or security fixes, mainly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants