Skip to content

fix(service-worker): do not unassign clients from a broken version - #43518

Closed
gkalpak wants to merge 3 commits into
angular:masterfrom
gkalpak:fix-sw-failed-version
Closed

gkalpak wants to merge 3 commits into
angular:masterfrom
gkalpak:fix-sw-failed-version

Conversation

@gkalpak

@gkalpak gkalpak commented Sep 20, 2021

Copy link
Copy Markdown
Member

Previously, when a version was found to be broken, any clients assigned to that version were unassigned (and either assigned to the latest version or to none if the latest version was the broken one). A version could be considered broken for several reasons, but most often it is a response for a hashed asset that eiher does not exist or contains different content than the SW expects. See #28114 (comment) for more details.

However, assigning a client to a different version (or the network) in the middle of a session, turned out to be more risky than keeping it on the same version. For angular.io, for example, it has led to #28114.

This commit avoids making things worse when identifying a broken version by keeping existing clients to their assigned version (but ensuring that no new clients are assigned to the broken version).

NOTE:
Reloading the page generates a new client ID, so it is like a new client for the SW, even if the tab and URL are the same.

@google-cla google-cla Bot added the cla: yes label Sep 20, 2021
@gkalpak gkalpak added area: service-worker Issues related to the @angular/service-worker package target: patch This PR is targeted for the next patch release type: bug/fix labels Sep 20, 2021
@ngbot ngbot Bot added this to the Backlog milestone Sep 20, 2021
@gkalpak
gkalpak force-pushed the fix-sw-failed-version branch from 48911b5 to cb55d21 Compare September 20, 2021 17:57
@mary-poppins

Copy link
Copy Markdown

@gkalpak
gkalpak marked this pull request as ready for review September 20, 2021 18:37
@gkalpak
gkalpak requested a review from IgorMinar September 21, 2021 07:58
Previously, a ServiceWorker test was using the
`MockServerState#sawRequestFor()` method. This method, however, only
returns a boolean indicating whether a request had been seen, but would
not throw an error in either case.

Since the intention was to assert that a specific request was made, this
commit switches to the correct `MockServerState#assertSawRequestFor()`
method.
Previously, when a version was found to be broken, any clients assigned
to that version were unassigned (and either assigned to the latest
version or to none if the latest version was the broken one). A version
could be considered broken for several reasons, but most often it is a
response for a hashed asset that eiher does not exist or contains
different content than the SW expects. See
angular#28114 (comment)
for more details.

However, assigning a client to a different version (or the network) in
the middle of a session, turned out to be more risky than keeping it on
the same version. For angular.io, for example, it has led to angular#28114.

This commit avoids making things worse when identifying a broken version
by keeping existing clients to their assigned version (but ensuring that
no new clients are assigned to the broken version).

NOTE:
Reloading the page generates a new client ID, so it is like a new client
for the SW, even if the tab and URL are the same.
@gkalpak gkalpak added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 21, 2021
@gkalpak
gkalpak force-pushed the fix-sw-failed-version branch from cb55d21 to ab5e790 Compare September 21, 2021 10:19
@mary-poppins

Copy link
Copy Markdown

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

@IgorMinar IgorMinar added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 23, 2021
@IgorMinar

Copy link
Copy Markdown
Contributor

Thank you, @gkalpak!!!

@alxhub alxhub closed this in f149724 Sep 24, 2021
alxhub pushed a commit that referenced this pull request Sep 24, 2021
…43518)

Previously, when a version was found to be broken, any clients assigned
to that version were unassigned (and either assigned to the latest
version or to none if the latest version was the broken one). A version
could be considered broken for several reasons, but most often it is a
response for a hashed asset that eiher does not exist or contains
different content than the SW expects. See
#28114 (comment)
for more details.

However, assigning a client to a different version (or the network) in
the middle of a session, turned out to be more risky than keeping it on
the same version. For angular.io, for example, it has led to #28114.

This commit avoids making things worse when identifying a broken version
by keeping existing clients to their assigned version (but ensuring that
no new clients are assigned to the broken version).

NOTE:
Reloading the page generates a new client ID, so it is like a new client
for the SW, even if the tab and URL are the same.

PR Close #43518
alxhub pushed a commit that referenced this pull request Sep 24, 2021
Previously, a ServiceWorker test was using the
`MockServerState#sawRequestFor()` method. This method, however, only
returns a boolean indicating whether a request had been seen, but would
not throw an error in either case.

Since the intention was to assert that a specific request was made, this
commit switches to the correct `MockServerState#assertSawRequestFor()`
method.

PR Close #43518
alxhub pushed a commit that referenced this pull request Sep 24, 2021
…43518)

Previously, when a version was found to be broken, any clients assigned
to that version were unassigned (and either assigned to the latest
version or to none if the latest version was the broken one). A version
could be considered broken for several reasons, but most often it is a
response for a hashed asset that eiher does not exist or contains
different content than the SW expects. See
#28114 (comment)
for more details.

However, assigning a client to a different version (or the network) in
the middle of a session, turned out to be more risky than keeping it on
the same version. For angular.io, for example, it has led to #28114.

This commit avoids making things worse when identifying a broken version
by keeping existing clients to their assigned version (but ensuring that
no new clients are assigned to the broken version).

NOTE:
Reloading the page generates a new client ID, so it is like a new client
for the SW, even if the tab and URL are the same.

PR Close #43518
@gkalpak
gkalpak deleted the fix-sw-failed-version branch September 24, 2021 20:09
gkalpak added a commit to gkalpak/angular that referenced this pull request Oct 2, 2021
This commit updates angular.io to the latest stable version of the
Angular framework (v12.2.8). Among other benefits, this version also
includes the ServiceWorker fix from angular#43518, which fixes angular#28114.

NOTE:
This commit also makes the necessary changes to more closely align
angular.io with new apps created with the latest stable Angular CLI.

Fixes angular#28114
dylhunn pushed a commit that referenced this pull request Oct 5, 2021
This commit updates angular.io to the latest stable version of the
Angular framework (v12.2.8). Among other benefits, this version also
includes the ServiceWorker fix from #43518, which fixes #28114.

NOTE:
This commit also makes the necessary changes to more closely align
angular.io with new apps created with the latest stable Angular CLI.

Fixes #28114

PR Close #43687
gkalpak added a commit to gkalpak/angular that referenced this pull request Oct 5, 2021
…ion fails

When an app version is detected as broken, the SW calls the
`Driver#versionFailed()` method. Previously, this method would in turn
call the `Driver#sync()` method, which writes some metadata about the
SW's state to the `ngsw:/:db:contol` cache. More specifically,
`Driver#sync()` persists info about all known app versions, which one is
the latest and also what version each client is assigned to.

However, no relevant info is changed inside `Driver#versionFailed()`, so
the call to `Driver#sync()` is redundant (since there are no changes
that need to be synced with the cache). This is a left-over from
before angular#43518, when `Driver#versionFailed()` used to update version
assignments and thus did require synchronization with the cache.

This commit removes the redundant `Driver#sync()` call to avoid an
unnecessary write to the cache.
jessicajaniuk pushed a commit that referenced this pull request Oct 21, 2021
…ion fails (#43680)

When an app version is detected as broken, the SW calls the
`Driver#versionFailed()` method. Previously, this method would in turn
call the `Driver#sync()` method, which writes some metadata about the
SW's state to the `ngsw:/:db:contol` cache. More specifically,
`Driver#sync()` persists info about all known app versions, which one is
the latest and also what version each client is assigned to.

However, no relevant info is changed inside `Driver#versionFailed()`, so
the call to `Driver#sync()` is redundant (since there are no changes
that need to be synced with the cache). This is a left-over from
before #43518, when `Driver#versionFailed()` used to update version
assignments and thus did require synchronization with the cache.

This commit removes the redundant `Driver#sync()` call to avoid an
unnecessary write to the cache.

PR Close #43680
jessicajaniuk pushed a commit that referenced this pull request Oct 21, 2021
…ion fails (#43680)

When an app version is detected as broken, the SW calls the
`Driver#versionFailed()` method. Previously, this method would in turn
call the `Driver#sync()` method, which writes some metadata about the
SW's state to the `ngsw:/:db:contol` cache. More specifically,
`Driver#sync()` persists info about all known app versions, which one is
the latest and also what version each client is assigned to.

However, no relevant info is changed inside `Driver#versionFailed()`, so
the call to `Driver#sync()` is redundant (since there are no changes
that need to be synced with the cache). This is a left-over from
before #43518, when `Driver#versionFailed()` used to update version
assignments and thus did require synchronization with the cache.

This commit removes the redundant `Driver#sync()` call to avoid an
unnecessary write to the cache.

PR Close #43680
jessicajaniuk pushed a commit that referenced this pull request Oct 21, 2021
…ion fails (#43680)

When an app version is detected as broken, the SW calls the
`Driver#versionFailed()` method. Previously, this method would in turn
call the `Driver#sync()` method, which writes some metadata about the
SW's state to the `ngsw:/:db:contol` cache. More specifically,
`Driver#sync()` persists info about all known app versions, which one is
the latest and also what version each client is assigned to.

However, no relevant info is changed inside `Driver#versionFailed()`, so
the call to `Driver#sync()` is redundant (since there are no changes
that need to be synced with the cache). This is a left-over from
before #43518, when `Driver#versionFailed()` used to update version
assignments and thus did require synchronization with the cache.

This commit removes the redundant `Driver#sync()` call to avoid an
unnecessary write to the cache.

PR Close #43680
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Oct 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: service-worker Issues related to the @angular/service-worker package cla: yes target: patch This PR is targeted for the next patch release type: bug/fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants