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
Service worker Invariant violated (initialize): latest hash null #25611
Comments
Sorry, but it is not possible to investigate this without a reproduction 😞 |
Very helpful. So unless I can provide a replication there can be no discussion to what the problem is and the issue just get closed. No explanation as to the what would cause that error then as that would be helpful, or do we have to guess and hope it fixes itself. |
Closing the issue doesn't mean there can be no discussion. I have no idea what might be causing the error (because afaict that error should never happen 😳). It is not impossible that this is a browser bug. But we can't investigate without a reproduction 🤷♂️ Regarding the registration issue, my guess is that it is unrelated to the error. Possibly related to #20970 (I can't really know without...you guessed it...a reproduction 😁) (Happy to continue the discussion below.) |
I had recently noticed that I was still getting this issue on one of my machines and as a result the following update message was never triggered. Once I'd completely cleared the browser cache on that machine the service worker no longer had the error and installed correctly. There must have been a bug in the service worker at some point which didn't get cleared in the updates. Thankfully the user base for this particular app is very small as wouldn't have been great trying to instruct a large number of users on how to fix it.
|
I also got this very same error with latest Angular (7.2). Unfortunately it is very hard to reproduce as it just happened in one installation. After the error, SW seems to bail out without actually executing ngsw-worker.js so it's bit hard to debug what's going on. I wish SW would just clear all the caches when it crashes so it would hopefully recover from the error next time user visits the site. |
After enabling 'Update on reload' in Chrome's service worker settings I was able to debug the issue. For some reason, in initialize() command const table = yield this.db.open('control'); would return empty object and hence bit later on, latest.latest; would equal to null. Because of this, this.versions.has(latest.latest) check would return null and 'Invariant violated (initialize)' exception was thrown. At this point I manually called this.cleanupCaches(); and this would fix the problem next time I reloaded the page. Problem here is of course that I had to check that developer option to be able to execute the code so this won't fix problems when SW is in error state (I think). I hope this information could help someone who actually knows more about the internals of Angular SW worker. |
@pleinonen, thx for providing extra info. If there is a problem reading Did you by any chance manually looked at the contents of the |
@gkalpak Unfortunately I cannot reproduce problem anymore after using the cleanupCaches-trick above. Of several instance I have, error did happen only once. However, I do remember clear that when hitting the break point at exception, latest.latest was indeed null. Not 'undefined' or anything like that. It was null. Everything else is bit vague I am afraid. I did peek 'manifest' and 'assignments' properties after this and they did not contain any sensible values either (empty object probably). Finally, I the steps to reproduce were something like this:
Could it be that the control table can be corrupted in during the update? |
Corruption might explain it. Maybe we should enter |
I see this error happening quite often. Here are some informations I collected from the debugger.
Chrome 72.0.3626.109, Angular 7.0.4 |
Thx for the info, @philipooo. I think I can see a path that could lead to having If the app sent a message to activate an update before running the SW initialization, then we could get a call chain like this: Not sure how that would happen, given that clients would not be notified about updates before initialization, but maybe it is worth ensuring that the private async handleMessage(msg: MsgAny&{action: string}, from: Client): Promise<void> {
+ if (this.initialized === null) {
+ this.initialized = this.initialize();
+ }
+ try {
+ await this.initialized;
+ } catch (e) {
+ this.state = DriverReadyState.SAFE_MODE;
+ this.stateMessage = `Initialization failed due to error: ${errorToString(e)}`;
+ ...
+ }
+
if (isMsgCheckForUpdates(msg)) {
...
} else if (isMsgActivateUpdate(msg)) {
...
}
} |
@philipooo, since you see this error happening often (and you seem to be already instrumenting your code to gather insights), it would be great if you could track calls to |
Thank you. Of course I will. When loading the app the methods called like this:
Payload of the handleMessage call
|
Thx @philipooo. Have you verified whether the Could you check that, @philipooo? |
Sorry for the delay. I am not sure whats the best sufficient way to debug the completion of the async calls. Can you give me some tips? (Chrome Dev Tools) Update What I see is:
I am not sure, but I think this means If you can give me some lines where I should place breakpoints I would be happy to do this. |
Thx, @philipooo. I a little confused by your findings. If this line is hit (as you mentioned), then the SW should be in Also, I am not sure if setting break points is a good way to debug this, since break points affect the timing of certain operations (so they can cover or cause race condition issues). I would be better if you could modify the SW script file to log when certain things happen (e.g. If you can do that and still reproduce the |
Yes its because of the mentioned error. I tried to avoid modifing the SW script because I did not know if this would influence the reproducability of the error. But as there is no sufficient way debugging with breakpoints I will try to modifiy the script now. Stay tuned. |
I tried instrumenting Instrumentation example
Output
|
Just got the error in our app recently, is it somehow connected to opened dev tools? Is there any workaround? Sounds like a major issue as it may prevent end users to run the app correctly. |
Hi everyone .. Same problem here: Error: ngsw-worker.js:2270 Uncaught (in promise) Error: Invariant violated (assignVersion): want AppVersion for null but not loaded the app throws error and crash chomre tab (all angular and chrome latest release) The app is hosted on firebase with SSR (on firebase functions). I've another app (same Angular version and on firebase and SSR on functions) and it work as aspected. Any news? THNX!! |
We have introduced the Here some additional information for our case (if it is a separate problem I guess/hope someone with deeper insight in the Problematic Current BehaviorThe service worker eventually ends up in (This is the message from #24333 since I messed up and forgot to copy+paste mine before I worked around it - I'll try to check if mine was actually identical when I get it the next time.)
This seems to happen only to some users on some updates, however eventually every test user with which we are in contact got this sooner or later. ReproductionImplement the EnvironmentTested with Notable thingsThe information provided by @philipooo was exactly the same in our case. Additionally I can say that in the problematic cases the Possibly related issues#24333, #22087, https://stackoverflow.com/questions/54455518/angular-service-worker-is-in-safe-mode Workarounds
And add the following line after the found code:
Since the |
Was it possible to make a patch for version 7.x.x? thx |
I'm afraid not. 7.x is in LTS mode, which means only critical fixes and security patches are released. |
I understand.. and 8.2.x ? |
…ngular#32525) - resolves "Invariant violated (initialize): latest hash null has no known manifest" - Thanks to @gkalpak and @hsta for helping test and investigate this fix Fixes angular#25611 PR Close angular#32525
…ngular#32525) - resolves "Invariant violated (initialize): latest hash null has no known manifest" - Thanks to @gkalpak and @hsta for helping test and investigate this fix Fixes angular#25611 PR Close angular#32525
…ngular#32525) - resolves "Invariant violated (initialize): latest hash null has no known manifest" - Thanks to @gkalpak and @hsta for helping test and investigate this fix Fixes angular#25611 PR Close angular#32525
Sorry for taking so long to get back. |
for those who use angular 7.x...
|
Big WARNING: |
@gkalpak - I know this ticket is closed, but I was not sure where else to post this. With the patch applied, I have still gotten the error on at least one machine (code not yet released to users) The good news is that the browser is still served the new version of the application instead of the old one if there is an update (which is a very huge improvement). I have looked through all the Angular SW APIs and it appears that there is no way for me to programmatically know that there is a failure and it appears there is no way to programatically recover from this. Do you have any advice on how I might detect the error and recover from this programmatically on a user-by-user basis?
|
@paustint, do you have a way to know whether the machine you saw this on had already updated to the new SW. Because, even if your app has been updated with the fix, I think it is still possible for the old SW to be activated and run into the issue before being replaced by the new one. Regarding recovering from this, the SW should be able to recover automatically (e.g. the next time it is instantiated, after clients have been closed). Can you check in the cache (e.g. in |
@gkalpak - I actually never merged any service worker code into my core codebase until just now, so while this computer did have the old service worker 4 months ago, it has accessed the application where no I am pretty confident this is the new service worker. The old service worker would have been dated sometime in early august and we have not used it in-between until now. I have released multiple new versions of the application, but this client fails every time. It DOES use the latest version of the code and not a cached version. |
@gkalpak - Looking at the code in the error, I do see the code that was added with the patch and did not previously exist. |
Hm...it could also be the case that this breaks because What happens if you clear the cache? Can you still reproduce the error? |
BTW, I assume this failing machine is not publicly accessible, right? |
The machine with the issue is a laptop and is not public facing.
I cleared the cache (clicked each entry and Eventually I clicked the "update on reload" checkbox in chrome devtools and after a page refresh the service worker did recover and is now working on this machine. I will keep an eye on it through staging and production to see if the error pops up again, but I am really hopeful that the error will not occur again. |
Thx for the update, @paustint 👍 |
We had the same issue too and it is persistent when user has old version of app with cache issue then window.caches.open('ngsw:/:db:control').then(cache => cache.delete('/latest').then(remove => console.info('cache storage ngsw /latest removed'))) |
Weird that I couldn't reproduce it on https://next.angular.io/, but 🤷♂ (Also, I would be very interested to know if the error happens again once updated to the latest SW, so let me know here 🙏) |
After updating:
When app is deployed and a new version is available, I started to get service worker errors. In console I get such error:
However, ngsw/state shows this:
In code I subscribe to swUpdate.available event and check for updates manually (on every successful login to the app). In Chrome event is fired, in Firefox - sometimes yes, sometimes not. However, all above is true for chrome in incognito mode, or for Chrome on my colleagues laptops, that are not developing Angular, using devtools etc. On my Chrome instance, not incognito mode, ngsw/state always shows this:
What I am afraid of is that service worker does not work not only for me, but may not work stable enough for end users too. I would be happy to provide more info or event sequence how all of this happens, if that would help to fix these problems. |
@prp1, it is not exactly clear to me what fails and when. Are you saying this happens even after you clear the cache and SW (e.g. Chrome DevTools > Application > Clear storage > Clear site data)? If so, could you try to debug this and get an (async) stack trace of the rejection (i.e. what function calls lead to the rejected promise)? |
I haven't cleared the cache and SW (e.g. Chrome DevTools > Application > Clear storage > Clear site data). After doing this, everything again works as expected. Is it known what could have caused the need to clear the cache and SW? Is it possible that simple users will need to do the same? If yes, is it known how to fix the issue programmatically? |
I haven't been able to reproduce this, but some people have reported that if the cache was in a bad state (from a previous SW version) than the latest SW would fail to recover. If someone can provide a reproduction of this, I would be happy to investigate the root cause. In the meantime, PRs making the SW more robust to a bad cache are welcome (see #25611 (comment)). I can't really say how this can be fixed programmatically (because it is not clear to me what is causing the problem), but if it is related to the caches you can delete them by doing something similar to the SW's deleteAllCaches() method. It would look something like this: caches.keys().
then(cacheNames => cacheNames.filter(name => name.startsWith(`ngsw:`))).
then(cacheNames => Promise.all(cacheNames.map(name => caches.delete(name)))); Both the page and the SW share the same |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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. |
I'm submitting a...
Current behavior
Firstly I'm unable to get the service worker to register using
I have to use the following in my main.ts
and when I test locally the service worker registers fine. But after I deploy to my server the service worker fails to register with the following error
maybe this is why the recommended way to register the service worker fails, although unsure on that as I don't get any errors.
Expected behavior
The service worker was installed using angular cli and has been setup without any changes and is installed as per the documentation, however this doesn't work.
Minimal reproduction of the problem with instructions
As the issue can't be replicated locally there's little value in providing code. Need to understand why the same production build works locally but doesn't when deployed.
Environment
The text was updated successfully, but these errors were encountered: