HomePhabricator
Diffusion Comm 7a071de9cb5b

[web] make sure all tabs and worker are operating on the same web version

Description

[web] make sure all tabs and worker are operating on the same web version

Summary:
ENG-6326

The initial solution I was thinking of is:

  1. Store content hash (of .wasm file) in worker memory.
  2. Each time a new tab is opened compare content hashes.
  3. On difference kill the worker and initialize again to fetch a new bundle.
  4. Reload old tabs.

A couple of issues with this:

  1. There is no easy way to terminate a worker. Terminate does not work for Shared Workers, close only clear task queue, and does not cause re-fetching worker script.
  2. We can close all tabs, leave only the newest one, and refresh - this doesn't make any sense.
  3. We can refresh all tabs at once - this is very hard to implement because it must be done simultaneously. There is a risk of race condition, when with multiple tabs first already finished refreshing when the latest has not started yet.

That being said, I am proposing a simpler and safer solution:

  1. We create a worker, which name is associated with the web version - when we open a new tab with the new version we will create new Shared worker with the newest bundle (which is in sync with main thread and .wasm file).
  2. We broadcast (supported by all browsers) current version to other tabs.
  3. When we receive the version we compare it, if it's different this tab is old, we refresh it - download the newest web app version, and connect to the new worker.
  4. After all tabs are reloaded, the old worker dies (there is no connection to it).
  5. When we open a new tab with the new version, old tabs are in the background so it should be safe because the worker should not be performing anything on DB.

Test Plan:

  1. Run prod web app (hot reloading messes up this test)
  2. Open a couple of tabs
  3. Bump web codeVersion
  4. Run the prod web app again
  5. Open a new tab, which should cause reloading old tabs, bumping spawning new worker with a name including new version, killing an old worker.
  6. Inspect the network tab to make sure that to create a worker with a new name script is fetched.
  7. Tested on Chrome, Firefox, and Safari (on Safari there is no way to inspect workers, so I based this test only on information on whether old tabs were reloaded).

Reviewers: tomek, michal

Reviewed By: tomek, michal

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D10592

Details

Provenance
kamilAuthored on Jan 10 2024, 5:41 AM
Reviewer
tomek
Differential Revision
D10592: [web] make sure all tabs and worker are operating on the same web version
Parents
rCOMM2b34d6446508: Enable backup creation and restoration from Rust
Branches
Unknown
Tags
Unknown