Skip to content

SwUpdate checkForUpdate can run multiple times simultaneously #49618

@henry-alakazhang

Description

@henry-alakazhang

Which @angular/* package(s) are the source of the bug?

service-worker

Is this a regression?

No

Description

If you call SwUpdate.checkForUpdate multiple times from application code, it is not deduplicated. Each call will do the full manifest fetch, and will attempt to install a new version if applicable, downloading all the assets multiple times. The assets themselves should mostly be cached by the browser, so there aren't excessive actual requests, but it does potentially slow down the SW thread with what should be completely unnecessary processing.

image

This is relevant for our application, as we run a regular background upgrade check on a timer. If a user has many tabs open, we can end up calling checkForUpdate multiple times. Ideally, these multiple calls do not actually trigger multiple downloads and updates.

note: the builtin checkForUpdate calls are all wrapped in the idle scheduler, so they do not have this issue. or, they kind of do, but it doesn't matter as much because they'll run in sequence and the later calls will just fetch the manifest once and do nothing.

If this functionality isn't desired, I should be able to make a PR to fix it.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    
Angular CLI: 14.2.10
Node: 16.14.2
Package Manager: yarn 1.22.15 
OS: darwin arm64

Angular: 14.2.12
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1402.10
@angular-devkit/build-angular   14.2.10
@angular-devkit/core            14.2.10
@angular-devkit/schematics      14.2.10
@angular/cdk                    14.2.5
@angular/cli                    14.2.10
@angular/fire                   7.4.1
@angular/material               14.2.5
@nguniversal/builders           14.2.3
@nguniversal/express-engine     14.0.3
@schematics/angular             14.2.10
rxjs                            7.5.7
typescript                      4.8.4

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: service-workerIssues related to the @angular/service-worker package

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions