Skip to content

Uncaught exception DomException #792

Closed

Description

@weeblr

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:

  1. 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

  1. Navigate the site, so that the SW is running and some content is saved to cache storage
  2. Using Chrome dev tools, clear storage, including: "Unregister service workers" and "Cache storage"
  3. Reload the latest page of the site, or navigate to another one that has some cached content
  4. 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

Activity

  1. jeffposnick commented on Sep 8, 2017

    @jeffposnick
    Contributor

    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.

  2. weeblr commented on Sep 8, 2017

    @weeblr
    Author

    Hi

    Thanks.

    it will also automatically stop and delete the registered service workers for that origin.

    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)

    sw:1 Uncaught (in promise) DOMException: Entry was not found.
    Promise rejected (async)
    f.getCache.then @ workbox-sw.prod.v2.0.0.js:77
    async function (async)
    f.getCache.then @ workbox-sw.prod.v2.0.0.js:77
    Promise resolved (async)
    fetchAndCache @ workbox-sw.prod.v2.0.0.js:77
    async function (async)
    fetchAndCache @ workbox-sw.prod.v2.0.0.js:77
    handle @ workbox-sw.prod.v2.0.0.js:89
    cacheRouteHandler @ wbamp-pwa-sw:163
    handleRequest @ workbox-sw.prod.v2.0.0.js:59
    _isListenerRegistered.self.addEventListener @ workbox-sw.prod.v2.0.0.js:59
    
  3. weeblr commented on Sep 8, 2017

    @weeblr
    Author

    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?

  4. jeffposnick commented on Sep 8, 2017

    @jeffposnick
    Contributor

    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 fetch handler 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".

  5. Pikachews commented on Nov 2, 2017

    @Pikachews

    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? 😕

  6. jeffposnick commented on Nov 2, 2017

    @jeffposnick
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions