-
Notifications
You must be signed in to change notification settings - Fork 575
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
web: mark as uncloneable when possible #3709
Conversation
This tells node that the marked instances from undici are not cloneable, so that attempts to cloning those throw `DataCloneError`.
I am hesitant to write a test here, as it would be like testing the behaviour of |
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.
lgtm
I really think having a test would be useful, add it. |
Why is Headers unclonable? |
AFAIK, any cloneable that wants to be cloned in node runtime needs to
One example you can find in node is https://github.com/nodejs/node/blob/00b2f07f9ddeb8ffd2fb2108b0ed9ffa81ea000d/lib/internal/webstreams/transfer.js#L49 I don't think the above are exposed, so undici classes are not cloneable in node from that sense. |
I didn't mean to close this. Sorry. |
How can we access those symbols from userland? |
@ronag it's because webidl platform objects cannot be cloned:
Notice that the webidl for Headers does not include serializable: [[Exposed](https://webidl.spec.whatwg.org/#Exposed)=(Window,Worker)]
interface Headers {
...
} |
I should've mentioned, this is more to tell Node to treat undici instances as a platform object, as this api will attach a private attribute that Node can recognize. Without it, Node will try to find the
I think whether/how we make some classes cloneable in undici should be a separate and broader discussion, since it might involve whether/how Node exposes its internal symbols. |
I also added the test. It works fine on my local but won't be effective on current CI, as the API hasn't been released. The API is on |
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.
why "maybeMarkAsUncloneable"? If in the future all supported platforms have markAsUncloneable, then do we need to rename this function and all the places where it is called?
More likely that we forget that in 3 years.
Good point. I updated the naming. |
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.
RSLGTM
btw. cloneable or clonable, is the spelling right?
Yeah, it's correct. In node it's always |
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.
Does this also need to be done for EventSource, WebSocket, WebsocketStream, CloseEvent, ErrorEvent, MessageEvent, Cache, CacheStorage, and possibly others?
I think we should. I was focusing on the classes that are exposed to node only. |
WebSocket, CloseEvent, and MessageEvent are exposed in node |
Yes, they've been updated within this PR. I think maybe every class under |
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.
lgtm
Can you please fix linting? |
Tagging as backportable |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-v6.x v6.x
# Navigate to the new working tree
cd .worktrees/backport-v6.x
# Create a new branch
git switch --create backport-3709-to-v6.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 1ab238207d84196479428494d52fc922833e8e5b
# Push it to GitHub
git push --set-upstream origin backport-3709-to-v6.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-v6.x Then, create a pull request where the |
@jazelly would you mind sending a backport commit with the instructions above? |
I am happy to do it. |
* web: mark as uncloneable when possible This tells node that the marked instances from undici are not cloneable, so that attempts to cloning those throw `DataCloneError`. * test: add test cases for platform objects uncloneable * fix: move to webidl * fix: move it under webidl * fixup: rename it to markAsUncloneable * fix: mark more web instances uncloneable * fixup --------- Co-authored-by: Khafra <[email protected]> (cherry picked from commit 1ab2382)
* web: mark as uncloneable when possible This tells node that the marked instances from undici are not cloneable, so that attempts to cloning those throw `DataCloneError`. * test: add test cases for platform objects uncloneable * fix: move to webidl * fix: move it under webidl * fixup: rename it to markAsUncloneable * fix: mark more web instances uncloneable * fixup --------- Co-authored-by: Khafra <[email protected]> (cherry picked from commit 1ab2382)
* web: mark as uncloneable when possible This tells node that the marked instances from undici are not cloneable, so that attempts to cloning those throw `DataCloneError`. * test: add test cases for platform objects uncloneable * fix: move to webidl * fix: move it under webidl * fixup: rename it to markAsUncloneable * fix: mark more web instances uncloneable * fixup --------- Co-authored-by: Khafra <[email protected]> (cherry picked from commit 1ab2382)
* web: mark as uncloneable when possible This tells node that the marked instances from undici are not cloneable, so that attempts to cloning those throw `DataCloneError`. * test: add test cases for platform objects uncloneable * fix: move to webidl * fix: move it under webidl * fixup: rename it to markAsUncloneable * fix: mark more web instances uncloneable * fixup --------- Co-authored-by: Khafra <[email protected]> (cherry picked from commit 1ab2382)
Rationale
This tells node that the marked instances from undici are not cloneable, so that attempts to cloning those throw
DataCloneError
.This is a follow-up work from nodejs/node#55234
Changes
Marked the following as uncloneable.
Features
Bug Fixes
Breaking Changes and Deprecations
Status