-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PWA that polls the server never updates to a newer version #40207
Comments
Thx for the very detailed reproduction, @tmtron ❤️ 🤩 💯 So, here is what happens: So, since your app is constantly polling (i.e. sending requests), the SW will never consider itself idle and therefore will never perform the check-for-updates task. Note: This is not related to the requests failing or succeeding. It just happens that when the request fails, your app will send a new one before the 5s idle threshold. Despite the fact that it is probably not a good idea for an app to constantly make the same request when it fails (for example, there should be some backoff mechanism), the SW should be able to handle that more gracefully 😁 I will send a PR to make it so that the IdleScheduler has a max delay (say 30s) after which it executes its pending tasks even if the SW is not considered "idle". As far as work-arounds go, there are several things one could do on the client to avoid this issue:
Of course, none of these will help you if you can't update your client code (because the SW keeps serving the old version) 😅 I am afraid, the only thing you can do from the server is return a 2xx response for the polling request (so that the app stops polling and the SW can update itself. Alternatively (or in addition) you could configure the server to include the Clear-Site-Data header (with the |
Thanks for the fast and detailed response.
Funny, that exactly this "improvement" has now caused this issue :)
Sounds like a good idea, but as always, defining the right timeout is tricky. e.g.
That's what our (old) app does, but unfortunately, it waits until the angular app is idle, as mentioned in the docs: https://angular.io/guide/service-worker-communications#checking-for-updates So in the new version, we will check for updates right away, no matter if the app is stable or not.
Yes, that's also the workaround that we came up with. And it essentially means that we can never remove this endpoint from our server app. So from my side, the issue is resolved. Thanks! |
Thx for getting back, @tmtron!
These would be valid concerns, but fortunately this is not how SWs work 😃 So, if we add a 30s max delay, at most 30s after the user opens the broken page, the tasks will run (regardless of what the user does, i.e. regardless of whether the user stays on the page or not). Note that the max delay is only relevant if the user stays on a page that continues to make requests (which prevents the SW from going idle). If the user closes the page (i.e. the SW stops receiving requests), then the scheduled tasks will be executed after 5 secs.
Obviously, that technique will only work if the app does become stable at some point 😁 I am going to close this issue since you have been able to solve it on your end and there is nothing that can be done to fix the issue from the client-side at this point. (Feel free to continue the discussion below, if needed.) I'll send the PR to add the max delay in |
…ng the server Previously, the SW would wait to become idle before executing scheduled tasks (including checks for newer app versions). It was considered idle when it hadn't received any request for at least 5 seconds. As a result, if the app performed polling (i.e. sent requests to the server) in a shorter than 5 seconds interval, the SW would never detect and update to a newer app version. Related issue: angular#40207 This commit fixes this by adding a max delay to `IdleScheduler` to ensure that no scheduled task will remain pending for longer than the specified max delay.
…ng the server Previously, the SW would wait to become idle before executing scheduled tasks (including checks for newer app versions). It was considered idle when it hadn't received any request for at least 5 seconds. As a result, if the app performed polling (i.e. sent requests to the server) in a shorter than 5 seconds interval, the SW would never detect and update to a newer app version. Related issue: angular#40207 This commit fixes this by adding a max delay to `IdleScheduler` to ensure that no scheduled task will remain pending for longer than the specified max delay.
…ng the server Previously, the SW would wait to become idle before executing scheduled tasks (including checks for newer app versions). It was considered idle when it hadn't received any request for at least 5 seconds. As a result, if the app performed polling (i.e. sent requests to the server) in a shorter than 5 seconds interval, the SW would never detect and update to a newer app version. Related issue: angular#40207 This commit fixes this by adding a max delay to `IdleScheduler` to ensure that no scheduled task will remain pending for longer than the specified max delay.
…ng the server (#40234) Previously, the SW would wait to become idle before executing scheduled tasks (including checks for newer app versions). It was considered idle when it hadn't received any request for at least 5 seconds. As a result, if the app performed polling (i.e. sent requests to the server) in a shorter than 5 seconds interval, the SW would never detect and update to a newer app version. Related issue: #40207 This commit fixes this by adding a max delay to `IdleScheduler` to ensure that no scheduled task will remain pending for longer than the specified max delay. PR Close #40234
…ng the server (#40234) Previously, the SW would wait to become idle before executing scheduled tasks (including checks for newer app versions). It was considered idle when it hadn't received any request for at least 5 seconds. As a result, if the app performed polling (i.e. sent requests to the server) in a shorter than 5 seconds interval, the SW would never detect and update to a newer app version. Related issue: #40207 This commit fixes this by adding a max delay to `IdleScheduler` to ensure that no scheduled task will remain pending for longer than the specified max delay. PR Close #40234
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 bug report
Affected Package
@angular/service-worker
Is this a regression?
Not sure.
Description
When the current app version constantly polls the server and this request always fails, the PWA will never update to the newer version.
Details
We have an active version of our app which starts polling the server right away to get some basic info - when the request fails, it retries after a second until the request succeeds.
We have had multiple versions of our app with this polling in place and the updates always worked fine.
Not sure if it's relevant, but our app uses
registrationStrategy: 'registerImmediately'
In the newest version, we have removed this polling feature: i.e. the old endpoint does not exist anymore on the server.
The problem now is, that the PWA never updates to the newer version: i.e. the browser still shows the old version which tries to poll the (non-existent) endpoint, and since this fails the app will retry after 1 second and so on.
More info:
🔬 Minimal Reproduction
Here is a minimal project to reproduce the issue: https://github.com/tmtron/pwa-test
The readme contains detailed information about how to build and reproduce the update issue.
🔥 Exception or Error
PWA does not update to new version
🌍 Your Environment
Angular Version:
This also happens in our production app which uses angular 10.
Anything else relevant?
Note, that the reproduction project uses the
http-server
package. We used this because it makes it easy to reproduce the issue without the need for a full web-server. In production we use ngingx.Related Stackoverflow question: PWA that polls the server never updates to a newer version
The text was updated successfully, but these errors were encountered: