postMessage does not send the message if worker thread is immediately put to sleep
Categories
(Core :: DOM: Service Workers, defect)
Tracking
()
People
(Reporter: roberto.vidal, Unassigned)
References
()
Details
(Keywords: testcase)
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Steps to reproduce:
Working example: https://github.com/jrvidal/message-port-repro
I have a main document (main), an iframe and workers spawned by the latter.
- We send a
MessagePort
from (main) to (iframe), and then from (iframe) to a fresh (worker). - (iframe) and (worker) share a SharedArrayBuffer.
- (worker) posts to the port and
Atomic.wait()
s using the SAB. - (main) receives the message and notifies (iframe).
- (iframe) calls
Atomic.notify()
and lets (worker) resume.
Actual results:
I see this in the console:
[iframe] start worker #0 iframe.js:14:15
[iframe worker #0] posting and sleeping worker.js:7:11
[iframe worker #0] posting and sleeping worker.js:7:11
[iframe] start worker #1 iframe.js:14:15
[iframe worker #1] posting and sleeping worker.js:7:11
[iframe worker #1] posting and sleeping worker.js:7:11
[iframe] start worker #2 iframe.js:14:15
[iframe worker #2] posting and sleeping worker.js:7:11
[iframe worker #2] posting and sleeping worker.js:7:11```
Ignoring the duplicated logs (??), this means that the receiving port on the main thread never gets a message, and the worker never unblocks.
There is a `TIMEOUT` constant in `worker.js` that can force the worker to wait for a bit before posting-and-blocking. With `TIMEOUT=-1` (no timeout) the issue is quite persistent. With `TIMEOUT=0` is more intermittent. With `TIMEOUT` around 100ms I can't observe the issue.
Expected results:
Not sure if this is _expected_ behavior, but Chrome (Chromium 97.0.4692.99) the worker is always awakened:
iframe.js:14 [iframe] start worker #0
worker.js:7 [iframe worker #0] posting and sleeping
root.js:11 [main thread] port received a message {counter: 0}
iframe.js:23 [iframe] awake worker #0
worker.js:13 [iframe worker #0] done waiting: ok
iframe.js:14 [iframe] start worker #1
worker.js:7 [iframe worker #1] posting and sleeping
root.js:11 [main thread] port received a message {counter: 1}
iframe.js:23 [iframe] awake worker #1
worker.js:13 [iframe worker #1] done waiting: ok
iframe.js:14 [iframe] start worker #2
worker.js:7 [iframe worker #2] posting and sleeping
root.js:11 [main thread] port received a message {counter: 2}
iframe.js:23 [iframe] awake worker #2
worker.js:13 [iframe worker #2] done waiting: ok
Reporter | ||
Comment 1•3 years ago
|
||
Closing, bad formatting
Updated•3 years ago
|
Description
•