-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat(extensions): Broadcast Channel API #10527
Conversation
c250184
to
f538efe
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'm getting BorrowMutErrors when I try to postMessage. I'll investigate.
thread 'main' panicked at 'already borrowed: BorrowMutError', runtime/metrics.rs:189:35
f538efe
to
f4ccb55
Compare
c71d60a
to
c220bcd
Compare
7735044
to
8fc6262
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.
@lucacasonato This is ready for review. I've left some comments.
cli/tests/integration_tests.rs
Outdated
.arg("--location") | ||
.arg("http://127.0.0.1/") | ||
.arg("--allow-read") | ||
.arg("--no-check") // TS typechecking makes the test hang. |
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.
Because it tries to typecheck the inline script.
// Defer to avoid starving the event loop. Not using queueMicrotask() | ||
// for that reason: it lets promises make forward progress but can | ||
// still starve other parts of the event loop. |
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 observe that with queueMicrotask()
e.g. setTimeout()
callbacks don't run when ping-ponging messages over a BroadcastChannel.
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.
As always, implementation is very clean. Nice work. Mostly just some nitpicks.
I do want to voice some concerns regarding how the resources work. Currently there is one broadcast channel resource for all BroadcastChannel
s in an isolate. This is unfortunate because it makes the resource sanitizer in tests less effective. Say you create a BC outside a test, then another one in a test, and you don't close the one in the test, then there will be no resource leakage warning. I assume this approach is a lot faster though, because less boundary crossings, so this isn't a blocker for me. Logically one resource per BroadcastChannel
would make more sense for me though.
@@ -0,0 +1,97 @@ | |||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. |
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.
What about feature flagging this entire file, and enabling it by default?
It's for reasons of correctness, not performance - that's just a happy accident. :-) WPT requires that messages are delivered to receivers in subscription order but If you feel really strongly, I could implement a |
Nope, with this background info it makes sense now. Lets leave it as is. |
4419d72
to
e9297ce
Compare
@lucacasonato How do I get the linter to pass? It's using an existing deno binary that doesn't know about the new |
@bnoordhuis Fixed now through merging #10652. Just merge with main / rebase |
e9297ce
to
37dc0c8
Compare
37dc0c8
to
c9861ca
Compare
The integration test appears to be hanging on the CI but I can't reproduce locally, it always passes (and in less than a second):
I've added an |
All green with the integration test disabled. @lucacasonato Ideas on how to move forward? I don't mind investigating further but I don't have any leads and I'd like to get this merged before the inevitable next round of merge conflicts. |
cli/tests/integration_tests.rs
Outdated
@@ -2715,6 +2715,25 @@ console.log("finish"); | |||
assert!(end - start < Duration::new(10, 0)); | |||
} | |||
|
|||
#[test] | |||
#[ignore] // Hangs on CI, passes locally. | |||
fn broadcast_channel() { |
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.
So this is a integration test instead of a JS unit test because it requires --ignore?
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.
Because it requires --location
.
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.
Oh... don't we run unit tests with --location
? If not, @bartlomieju any objections to doing that?
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.
We do:
--location=http://js-unit-tests/foo/bar
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.
Oh, I remember the other issue: the test hangs when run as a unit test because deno test
tries to type-check the embedded script. I guess I'll move it to a separate file.
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.
@bnoordhuis I can get the test to pass without --no-check
.
I will take a quick look and see if I can get it to fail / pass, but if not let's merge it and investigate later. |
Found it - wrong assumption about worker startup being sync. |
5b4b110
to
f390896
Compare
Thanks for helping debug. I've turned it into a unit test and Luca pointed out how to fix the race. |
constructor(name) { | ||
super(); | ||
|
||
window.location; |
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.
This should be done in Rust.
Tried it out locally, and seems to work well. I have just two concerns left to address now:
|
Co-Authored-By: Ben Noordhuis <[email protected]> Fixes: denoland#10354
f390896
to
a782b61
Compare
I've added a Since it's behind |
Replaces the file-backed provider by an in-memory one because proper file locking is a hard problem that detracts from the proof of concept. Teach the WPT runner how to extract tests from .html files because all the relevant tests in test_util/wpt/webmessaging/broadcastchannel are inside basics.html and interface.html.
a782b61
to
c1f9393
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.
LGTM - the origin handling is incorrect (as shown by the broken WPT), but that is fine for now. We will need to revisit it when we do cross process BroadcastChannel
.
Thanks for sitting through this @bnoordhuis :-)
Sorry @crowlKats, something went wrong while merging. I used rebase-without-squash with the intent of keeping you as the author of the first commit but for some reason I show up as the author. Mea culpa. |
Current approach is wrong and doesn't work