fix(wall): hold the PCP holder in a Global, not a Persistent - #387
Merged
Conversation
szegedi
requested review from
IlyasShabi,
nsavoire and
r1viollet
as code owners
August 7, 2026 08:51
Overall package sizeSelf size: 2.46 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 |
|
🔗 Commit SHA: 4677a01 | Docs | Datadog PR Page | Give us feedback! |
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
force-pushed
the
szegedi/pcp-use-global
branch
from
August 7, 2026 08:57
1f7e51d to
4677a01
Compare
szegedi
enabled auto-merge (squash)
August 7, 2026 09:37
nsavoire
approved these changes
Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Review follow-up on #385 (@nsavoire's two nits, both landed after merge).
Persistent -> Global
v8::Persistenthas no destruction behaviour — the handle leaks unless every path clears it by hand.v8::Globalreleases it in its own destructor, and is what every other handle in this file already uses:ContextPtr,cpedKey_,wrapObjectTemplate_,jsArray_. ThePersistentI introduced in #385 was the odd one out.Nothing was actually leaking, since
~PersistentContextPtralways reset the handle explicitly — but relying on that is exactly the footgun the docs warn about. WithGlobalthe release becomes structural, so the explicitReset()goes away with it.Worth recording why the manual handle existed at all: before #261 removed instance reuse,
PersistentContextPtrrecycled itself through a freelist and neededClearWeak/Resetto unregister and re-register the same object. With reuse gone, a handle lives exactly as long as its PCP, so there's nothing left forPersistent's manual semantics to buy.