-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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.
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
lib: decorate undici classes as platform interfaces #55178
Conversation
Review requested:
|
663ec95
to
e91bfab
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #55178 +/- ##
==========================================
+ Coverage 88.39% 88.41% +0.01%
==========================================
Files 652 652
Lines 186565 186591 +26
Branches 36046 36051 +5
==========================================
+ Hits 164916 164971 +55
+ Misses 14908 14896 -12
+ Partials 6741 6724 -17
|
Node recognizes platform/host objects by counting internal slots. Undici, as a downstream module, does not have access to internal slots, and hence its instances are recognized as plain objects. This caused issues on the `structureClone` algorithm, which has few restrictions on non-platform objects. This PR tries to fix it by decorating Undici classes with the internal slots so that underlying `Serialize()` can recognize its instances as host objects. On another note, this PR consolidates the lazy loading of Undici, so that the proxied Undici classes are referential equal.
I'm a bit at a loss in why we want to keep that symbol private. Wouldn't it benefit everyone to allow a public way to configure this? On the issue, I think we might be better off in applying this change during the "build" |
FWIW, we can expose the symbol, but userland can mutate that value and make an object that was supposed to be transferable but now non-transferable, or vice versa. Although this is not unprecedented (think about the concept I am open to suggestions for this one, but I kept it as is in this PR as it looks like from the initial design, and changing that I think is pending a decision.
This is achievable once the symbol is public accessible.
My understanding is the performance penalty is there but not much from this fix, as the module is lazy loaded once only. The benchmark CI should provide more insights. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe undici can use this public API to mark an object as not transferable: https://nodejs.org/api/worker_threads.html#workermarkasuntransferableobject.
A new API can be added to mark an object as not cloneable, like worker.markAsUncloneable(object)
, along side with https://nodejs.org/api/worker_threads.html#workermarkasuntransferableobject..
Ah, that will work better. I didn't know that. I think this PR should be closed then. I can raise a new PR to add that API. |
External modules need a way to decorate their objects so that node can recognize it as a host object for serialization process. Exposing a way for turning off instead of turning on is much safer. PR-URL: #55234 Refs: #55178 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]> Reviewed-By: Matthew Aitken <[email protected]>
External modules need a way to decorate their objects so that node can recognize it as a host object for serialization process. Exposing a way for turning off instead of turning on is much safer. PR-URL: #55234 Refs: #55178 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]> Reviewed-By: Matthew Aitken <[email protected]>
External modules need a way to decorate their objects so that node can recognize it as a host object for serialization process. Exposing a way for turning off instead of turning on is much safer. PR-URL: nodejs#55234 Refs: nodejs#55178 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]> Reviewed-By: Matthew Aitken <[email protected]>
External modules need a way to decorate their objects so that node can recognize it as a host object for serialization process. Exposing a way for turning off instead of turning on is much safer. PR-URL: nodejs#55234 Refs: nodejs#55178 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]> Reviewed-By: Matthew Aitken <[email protected]>
Node recognizes platform/host objects by counting internal slots.
Undici, as a downstream module, does not have access to internal slots,
and hence its instances are recognized as plain objects. This caused
issues on the
structureClone
algorithm, which has few restrictions onnon-platform objects.
This PR tries to fix it by decorating Undici classes with the internal
slots so that underlying
Serialize()
can recognize its instances ashost objects.
On another note, this PR consolidates the lazy loading of Undici, so
that the proxied Undici classes are referential equal.
Fixes: #55120