RESOLVED FIXED 250839
SharedWorkerGlobalScope.close() does not then allow the SharedWorker to be replaced
https://bugs.webkit.org/show_bug.cgi?id=250839
Summary SharedWorkerGlobalScope.close() does not then allow the SharedWorker to be re...
Nathan
Reported 2023-01-19 07:48:51 PST
I've created a git repo with a test project demonstrating the bug here: https://github.com/shareup/sharedworker-restart-webkit-bug To replace or restart a `SharedWorker`, the shared worker can call `self.close()` on itself, then a window can use `new SharedWorker('worker.js')` to create and connect to a new worker. The expectation is `new SharedWorker('worker.js')` will always either connect to an existing, running `SharedWorker`, or boot one. It's important to be able to replace a `SharedWorker` when non-backwards compatible code is deployed, and still have the guarantee that there is only ever zero or one shared worker is running (by always using the same pathname `'worker.js'`). After `SharedWorkerGlobalScope.close()` is called, any other window which uses `new SharedWorker(worker.js)` will get a broken `SharedWorker`. I can see an HTTP request is made for `worker.js` (I don't have any headers which would cache the request), so WebKit is correctly loading the file from the network. However, it appears to never start up the shared worker or connect. The only remedy appears to be to close all tabs/windows which ever connected to the original `SharedWorker` (which is now closed), then `new SharedWorker('worker.js')` in a new window will work as expected again. I've tested in Safari 16 on macOS and iOS and in Safari Tech Preview on macOS and they all work the way I describe above. The test in the linked repo will close, and recreate the same `SharedWorker` 5 times in the same window session and works correctly in other UAs which support `SharedWorker`, but not in WebKit.
Attachments
Chris Dumez
Comment 1 2023-01-20 07:51:27 PST
I will take a look, thank you for the bug report.
Chris Dumez
Comment 2 2023-01-20 08:54:55 PST
Looks like I am able to reproduce with the provided test case: NO: SharedWorker failed to connect; count: 2
Chris Dumez
Comment 3 2023-01-20 09:36:30 PST
(In reply to Chris Dumez from comment #2) > Looks like I am able to reproduce with the provided test case: > NO: SharedWorker failed to connect; count: 2 We were not properly communicating that the SharedWorker had closed to our controller process. After fixing this: OK: Successfully shutdown and reconstructed the SharedWorker many times 🙌; count: 5 Will clean up the patch and write an automated test.
Radar WebKit Bug Importer
Comment 4 2023-01-20 10:34:40 PST
Chris Dumez
Comment 5 2023-01-20 12:05:22 PST
EWS
Comment 6 2023-01-23 11:44:07 PST
Committed 259228@main (76527da41c80): <https://commits.webkit.org/259228@main> Reviewed commits have been landed. Closing PR #8887 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.