-
Notifications
You must be signed in to change notification settings - Fork 423
Implement MessageChannel/MessagePort #3813
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
Conversation
The generated output of |
f70ff95
to
affb93a
Compare
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 think we should have a subset of MessagePort web-platform tests that validate this. If not, I'm afraid we're going to introduce yet another implementation that is not fully spec compliant.
That's a given. We won't be able to run the full web-platform test suite since it requires web workers in many cases. Before this is taken out of draft the tests will be greatly expanded and there will be more verifications that we are as close to spec conformance as possible. That said, this won't be fully spec compliant out of the box. Transfer lists will not be supported and the behavior will likely be closer to what Node.js has implemented than to what browsers implement. |
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 had started reviewing some code details but then at some point realized that unfortunately the overall design here might have a fatal flaw -- I don't think you can send a new MesasgePort across an existing MessagePort as designed, but I believe this is a requirement. See my first comment thread below... this might require a totally different design.
So... You can probably ignore the implementation comments since I suspect much of the implementation will have to change to solve this anyway...
affb93a
to
ba759f3
Compare
af8d9ad
to
93da298
Compare
742fc01
to
b119a25
Compare
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.
Can we put this behind an experimental flag or include the web platform tests, before landing it?
See the last commit in the set for discussion of web platform tests. We don't want to block on that indefinitely as we have a customer that needs this as soon as possible and the minimum of what we need is what they need to support their use of via undici. As for putting this behind an experimental, same. We will need this to be available outside of experimental. |
If we're going to add web platform tests, which will require a compat flag to fix any WPT bug, I'm not sure if we should land this as is. Regardless, of WPT, I think we put it behind a compat flag. This will likely break people since this is a global variable. And any application that checks if MessagePort includes will behave differently. |
Does undici work now that we have this? |
That'll be the next validation point. We need to have the customer test it... FWIW, undici does not actually use Also, keep in mind that there might be other reasons undici might not work, this is just the one we know for sure based on what the customer has asked for. |
-1 on this. We can use a I will look at adding a compat flag for the global exposure. |
f6b458b
to
e791b82
Compare
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.
Thank you
While this should otherwise be ready to land, I want to hold off just a bit until we get confirmation from the customer that it's going to meet the need they have. (I also think I might need to tweak the internal branch to get internal tests working but I'm going to hold off on that until I get confirmation on the customer question). |
This is an initial sketch of a MessageChannel/MessagePort impl.
e791b82
to
9bbb3d7
Compare
9dd9c07
to
cbb60a7
Compare
This is a
initial sketch of aMessageChannel/MessagePort impl. Why? Thank you for asking.. two reasons:MessageChannel
.This is a work in progress. PR will remain draft until all of the design/impl questions are answered but I'm opening this to start getting review.Or when used with JSRPC...JSRPC support deferred to laterThere are a range of open questions here that need to be figured out before this lands:1. Currently, when sending a port over rpc, the local version of that port is still usable. This is because jsrpc does not necessarily imply transfer semantics. So in the above jsrpc example, port2 is still usable locally and we actually have a one-to-many relationship now from port1 to port2 and port1 to the remote port on the rpc remote. That feels a bit weird.4. I've no idea if the underlying capnp rpc mechanism here is entirely correct. Is the output gate usage correct? Do we need a registerPendingEvent in here somewhere, etc. Specifically, should both sides of the jsrpc be kept alive so long as the message ports are connected and not closed? There are a range of behavioral things we should consider here. Simply... how do we expect things to behave where there are active ports spread across the rpc connection?5. Right now the message cloning does not support the extended types like ReadableStream and WritableStream. It probably should? But, should that also be supported if we're not cloning across a jsrpc boundary and everything is just local. Specifically, what should the cloning behavior be in the local-to-local case vs. the local-to-remote-rpc case?6. This does not implement the transfer list at all, is there a way to do so reasonably?This still needs a lot more tests, so the PR will remain draft until the tests are expanded and more of these questions are answered.