-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Clarify sync vs async nature of Worker::postMessage #5485
Comments
I am happy to write the WPT once we have determined what the expected behavior is. (Just one thing to clarify: While the example by @RReverser is written using SABs and |
Yeah they're here just for visibility; I could use something as simple as Hence, I think Atomics make a better base for a WPT. |
Nice find. This probably isn't helped with browsers typically having same-thread, cross-thread, and cross-process paths for messaging (and might not use Ideally (see also the end of https://infra.spec.whatwg.org/#algorithms):
|
As long as this doesn't result in That is, I think implementation-specific delays in |
By becoming "async" do you mean "queues a task"? And |
Yeah. I'd rather hope that both would become "synchronous" (not blocked on current thread).
Oh yeah, sorry, I forgot that this context got lost in the Twitter thread. I meant messaging from worker to main window, which currently works as expected across browsers. E.g.: new Worker(`data:text/javascript,
postMessage(42);
while(true);
`).onmessage = e => console.log(e.data); Prints 42 everywhere. |
Yeah, I agree that's what we should aim for. |
Ok; I'll try and prepare a WPT test. |
Per spec postMessage should queue a message up on the target port immediately. Instead, when Workers are involved, some implementations queue a task up on current thread's event loop, which means that in case it gets blocked, some messages are never sent. Resolves whatwg/html#5485.
Per spec postMessage should queue a message up on the target port immediately. Instead, when Workers are involved, some implementations queue a task up on current thread's event loop, which means that in case it gets blocked, some messages are never sent. Resolves whatwg/html#5485.
Per spec postMessage should queue a message up on the target port immediately. Instead, when Workers are involved, some implementations queue a task up on current thread's event loop, which means that in case it gets blocked, some messages are never sent. Closes whatwg/html#5485.
…vent loop, a=testonly Automatic update from web-platform-tests Test that postMessage doesn't block on event loop Per spec postMessage should queue a message up on the target port immediately. Instead, when Workers are involved, some implementations queue a task up on current thread's event loop, which means that in case it gets blocked, some messages are never sent. Closes whatwg/html#5485. -- wpt-commits: 3320205a9d70636efc03cfff340edecd0bee4694 wpt-pr: 23270
…vent loop, a=testonly Automatic update from web-platform-tests Test that postMessage doesn't block on event loop Per spec postMessage should queue a message up on the target port immediately. Instead, when Workers are involved, some implementations queue a task up on current thread's event loop, which means that in case it gets blocked, some messages are never sent. Closes whatwg/html#5485. -- wpt-commits: 3320205a9d70636efc03cfff340edecd0bee4694 wpt-pr: 23270
…vent loop, a=testonly Automatic update from web-platform-tests Test that postMessage doesn't block on event loop Per spec postMessage should queue a message up on the target port immediately. Instead, when Workers are involved, some implementations queue a task up on current thread's event loop, which means that in case it gets blocked, some messages are never sent. Closes whatwg/html#5485. -- wpt-commits: 3320205a9d70636efc03cfff340edecd0bee4694 wpt-pr: 23270 UltraBlame original commit: 69db48f9993a97aa33b2c1cfc8d424a81f0a6290
…vent loop, a=testonly Automatic update from web-platform-tests Test that postMessage doesn't block on event loop Per spec postMessage should queue a message up on the target port immediately. Instead, when Workers are involved, some implementations queue a task up on current thread's event loop, which means that in case it gets blocked, some messages are never sent. Closes whatwg/html#5485. -- wpt-commits: 3320205a9d70636efc03cfff340edecd0bee4694 wpt-pr: 23270 UltraBlame original commit: 69db48f9993a97aa33b2c1cfc8d424a81f0a6290
…vent loop, a=testonly Automatic update from web-platform-tests Test that postMessage doesn't block on event loop Per spec postMessage should queue a message up on the target port immediately. Instead, when Workers are involved, some implementations queue a task up on current thread's event loop, which means that in case it gets blocked, some messages are never sent. Closes whatwg/html#5485. -- wpt-commits: 3320205a9d70636efc03cfff340edecd0bee4694 wpt-pr: 23270 UltraBlame original commit: 69db48f9993a97aa33b2c1cfc8d424a81f0a6290
While debugging some cross-browser issues with using WebAssembly threads, I eventually ended up with the following pure-JS example that works differently in different browsers:
For this snippet in Firefox, you'll see messages "Spawned" and "Success" printed in the console, indicating that
postMessage
has sent a message synchronously (queued it up on the receiver end right away).In Chrome you'll only see "Spawned" and then the main thread gets blocked forever, which indicates that
postMessage
got queued up as a task on the main thread and so the Worker will never actually receive the message and won't be able to unblock the atomic.I've tried to read the relevant bits of the spec as well as looked for existing issues, and while some (e.g. #5078, #5327, #3691) sound relevant, I don't really understand what the correct behaviour is supposed to be here.
Could someone please clarify it and possibly add a WPT test so that I could file a bug for the corresponding browser? /cc @annevk @domenic @zcorpan @surma
The text was updated successfully, but these errors were encountered: