Repository navigation
Closed
Description
Library Affected:
workbox.js 2.0, workbox-runtime-caching
Browser & Platform:
Chrome 60, windows 10
Issue or Feature Request Description:
Under some circumstances, workbox.js can throw uncaught exceptions:
Uncaught (in promise) DOMException: Entry was not found.
Steps:
- Have a service worker that stores some content to cache. I use const ampCachingStrategy =
workboxSW.strategies.staleWhileRevalidate({
cacheName: getCacheName('content'),
cacheExpiration: {
maxEntries: 100
},
cacheableResponse: {
statuses: [0, 200],
headers: {
'x-pwa-cache': 'cache'
}
},
plugins: []
});
I suspect this would happen with other strategies, but I haven't tested
- Navigate the site, so that the SW is running and some content is saved to cache storage
- Using Chrome dev tools, clear storage, including: "Unregister service workers" and "Cache storage"
- Reload the latest page of the site, or navigate to another one that has some cached content
- You get the exception for each piece of cached content the SW is trying to retrieve
Uncaught (in promise) DOMException: Entry was not found.
Notes:
- this can be prevented by also stopping the SW from the Service Workers page, after clearing data, but before reloading the page
- IndexedDB (where expiration data is stored) is also cleared when using Clear storage
- Operation can be restored by closing the browser
- I suspect the SW is holding cache data in memory, which makes it try to load data from cache and fail with an exception
- I suspect this situation may happen in real life when a mobile phone automatically purges some cache data to reclaim space. Those exceptions prevent the normal operation of the SW until the browser is closed, or the SW manually stopped.
Am I missing something? is there something I can do in the SW code to handle those exceptions?
Rgds
Metadata
Metadata
Assignees
Labels
No labels
Activity
jeffposnick commentedon Sep 8, 2017
If Chrome determines that an origin has exceeded its available storage quota, then in addition to deleting the Cache Storage, IndexedDB, and anything else using space on disk, it will also automatically stop and delete the registered service workers for that origin. Those deletions are all-or-nothing, I would not expect users to automatically end up in the same state that you've manually entered by clearing storage while another client holds the service worker open.
I am not sure whether Firefox currently adheres to the same policy, but my suspicion is that it does.
Given that this is an artificially-induced error state, I'm not sure if it's something that Workbox would be able to cleanly recover from. But if you could share the stack trace associated with that logged error message I can take a look to see if there's any fallback logic that could be added anyway.
weeblr commentedon Sep 8, 2017
Hi
Thanks.
If this holds, then indeed this error is purely artificial (during local development), and should probably not be a major concern.
Here is a saved log: (chrome 61 now BTW)
weeblr commentedon Sep 8, 2017
Or another way to look at it might be that SW unregistered during the "Clear storage" process should also be sopped and deleted by Chrome?
jeffposnick commentedon Sep 8, 2017
FWIW, I just reproduced what you were describing with https://ifixit-pwa.appspot.com/ and confirmed that even though those messages get logged when attempting to retrieve entries from the cache, as long as a strategy that also involves the network is in used, the requests should eventually be fulfilled from the network. (As opposed to the exception being through and the
fetchhandler just giving up completely.) So I'm not sure that there's anything more that can be done from Workbox's side of things.You can pass along the feedback regarding the Chrome DevTools behavior you'd expect via https://bugs.chromium.org/p/chromium/issues/entry, filed against the component "Platform>DevTools".
Pikachews commentedon Nov 2, 2017
Some users of my site and I, myself, encountered this issue, despite not having messed with the browser's cache storage at all. It seems that the cache was cleared by the browser at some point, but the service worker associated with the site was not unregistered, causing this exact issue.
I also tested on the ifixit pwa by clearing the cache storage and refreshing the page, but the site does not recover from the issue on its own (I assume that is what you meant, @jeffposnick) until I unregister the service worker.
I also noticed that a hard refresh (Ctrl + Shift + F5, while devtools are open) would allow the site to load again, but still does not populate the cache storage until the service worker is unregistered, therefore refreshing once again would cause the issue.
Also, if you had tabs/windows using the same service worker, unregistering the service worker does not fix the issue until all but at most one of the tabs/windows are closed.
Is there really nothing that can be done about this? 😕
jeffposnick commentedon Nov 2, 2017
While it's possible that a browser could automatically clear the Cache Storage API for a given origin, the expected behavior is that automatic deletion would also delete the service worker registrations, to avoid leaving the browser in an inconsistent state. If a browser automatically clears the caches without deleting the service worker registration, then that's a browser bug. I'm sure relevant folks would like to investigate if you could provide reproduction steps via the Chromium issue tracker.
fix(service-worker): do not blow up when caches are unwritable (#26042)
fix(service-worker): do not blow up when caches are unwritable (#26042)
fix(service-worker): do not blow up when caches are unwritable (angul…