Skip to content
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

"Failed to execute 'transaction' on 'IDBDatabase': Database is Closing" exception on runtime cache #1661

Closed
lafayetteduarte opened this issue Sep 25, 2018 · 2 comments
Labels
Needs More Info Waiting on additional information from the community.

Comments

@lafayetteduarte
Copy link

lafayetteduarte commented Sep 25, 2018

Hi there,
I´m having some issues with workbox on chrome for android.
Workbox Version: : 3.4.1
loaded from: importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.4.1/workbox-sw.js');

Browser and platform: Google Chrome 69.0.3497.100 running on android 8.0
(the stacktrace below was copied from developer tools running USB debug).

Extra info on the behaviour:

  • The behaviour does not occour in a anonymous windows under the same conditions ( same browser / OS)

  • The behaviour does not occour on my desktop chrome ( same version as the mobile one). 69.0.3497.100 - 64 bits

  • when I run the website on a regular chrome tab, i do not see any databases under indexedDB.
    image

-when i do the same on the anonymous window, i can see the databases.

image

Edit 1:

It seems likely that a previous version of the IndexedDB database exists with the same name (i.e. one created by Workbox v2 code), so when the v3 Workbox code is running, its onupgradeneeded callback is never invoked, and thus the new object stores aren't created.

Stack trace ( visible while in USB Debug)

workbox-core.prod.js:1 Uncaught (in promise) DOMException: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
    at https://storage.googleapis.com/workbox-cdn/releases/3.4.1/workbox-core.prod.js:1:4385
    at new Promise (<anonymous>)
    at https://storage.googleapis.com/workbox-cdn/releases/3.4.1/workbox-core.prod.js:1:4347
    at Generator.next (<anonymous>)
    at n (https://storage.googleapis.com/workbox-cdn/releases/3.4.1/workbox-core.prod.js:1:167)
    at https://storage.googleapis.com/workbox-cdn/releases/3.4.1/workbox-core.prod.js:1:261

Here is my sw file:

importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.4.1/workbox-sw.js');


workbox.setConfig({
  debug: false
});


var maxAgeDay = 1 * 24 * 60 * 60; //01 days
var maxAgeMonth = maxAgeDay * 30; //30 Days
var maxAgeYear = maxAgeDay * 365;

//sharepoint useless static files
workbox.routing.registerRoute(
  /\/_layouts\/.*?\/.*?(\.js|gif|png|jpg|woff|css)/,
  workbox.strategies.cacheFirst({
    cacheName: 'sp-cache',
    plugins: [
      new workbox.expiration.Plugin({
        maxEntries: 60,
        maxAgeSeconds: maxAgeDay, 
        purgeOnQuotaError: true,
      }),
    ],
  }),
);
	
workbox.routing.registerRoute(
  /\/(WebResource.axd|ScriptResource.axd)\?d=*/,
  workbox.strategies.cacheFirst({
    cacheName: 'sp-cache-dyn',
    plugins: [
      new workbox.expiration.Plugin({
        maxEntries: 60,
        maxAgeSeconds: maxAgeMonth,
        purgeOnQuotaError: true,
      }),
    ],
  }),
);


//banner files
workbox.routing.registerRoute(
  /^https:\/\/.*?.domain.com.br\/(.*?\/)*(Banners|PublishingImages)\/(.*?)/gi,
  workbox.strategies.staleWhileRevalidate({
  	cacheName:'img-banners-destaques',
  	plugins: [
      new workbox.cacheableResponse.Plugin({
        statuses: [0, 200]
      }),
      new workbox.expiration.Plugin({
        maxEntries: 90,
        maxAgeSeconds: maxAgeDay,
        purgeOnQuotaError: true,
      })      
    ]
  })
);


workbox.routing.registerRoute(
  /\/Style(%20| )Library\/.*?\/.*?(\.css|js)/,
  workbox.strategies.staleWhileRevalidate({
  	cacheName:'js-css-style-lib',
  	plugins: [
      new workbox.cacheableResponse.Plugin({
        statuses: [0, 200]
      }),
      new workbox.expiration.Plugin({
        maxEntries: 90,
        maxAgeSeconds: maxAgeDay,
        purgeOnQuotaError: true,
      })      
    ]
  })
);

//fonts
workbox.routing.registerRoute(
  /\/Style(%20| )Library\/.*?\/.*?(\.woff|woff2|ttf|eot|svg)/,
  workbox.strategies.cacheFirst({
    cacheName: 'web-fonts',
    plugins: [
      new workbox.expiration.Plugin({
        maxEntries: 60,
        maxAgeSeconds: maxAgeYear,
        purgeOnQuotaError: true,      
      }),
    ],
  }),
);

//static-files-on subdomain
workbox.routing.registerRoute(
	/^https:\/\/static.domain.com.br\/web\//,
	workbox.strategies.staleWhileRevalidate({
		cacheName:'custom-static',
		plugins: [
			new workbox.cacheableResponse.Plugin({statuses: [0, 200]}),
          new workbox.expiration.Plugin({
            maxEntries: 90,
            maxAgeSeconds: maxAgeDay,
            purgeOnQuotaError: true,
          }) // 1 Days			
		]
	})
);

self.addEventListener('message', (event) => {
  if (!event.data){
    return;
  }

  switch (event.data) {
    case 'skipWaiting':
      self.skipWaiting();
      break;
    default:
      // NOOP
      break;
  }
});

thank you in advance

@philipwalton
Copy link
Member

Are you able to inspect the IndexedDB databases while debugging on your Android phone? If so, it could be helpful to see what's already there to better understand if an existing database or object store is causing the issue.

I'm skeptical that it is, though, because looking at the code, we now have upgrade logic for all instances of our IDB models, so they should be able to gracefully handle workbox v2 > v3 upgrade scenarios.

If you could narrow down what bit of code is causing the issue, that would also be helpful. Looking at your SW code, the only thing I see that uses IndexedDB is workbox.expiration.Plugin, if you remove that do you still see the error?

Also, it looks like workbox.expiration.Plugin creates an IndexedDB database with the same name as the cache name for the strategy including it. Is it possible that you have other code in your application that's created an IndexedDB database with the same name?

@jeffposnick maybe it's worth add a namespace to all database names we use in the future to minimize potential conflicts like this.

@philipwalton philipwalton added the Needs More Info Waiting on additional information from the community. label Oct 11, 2018
@lafayetteduarte
Copy link
Author

@philipwalton ,

Are you able to inspect the IndexedDB databases while debugging on your Android phone?

Yes. theres nothing there. no databases whatsoever ( see first print).

  • Removing the expiration plugin seems to work in this case.
  • upgrading to 3.6.2 fixed the issue on the device.

I suspect the issue is related to the bug described in #1640 .

Downgraded my QA server to 3.4.1 to collect diagnostics data . The same behaviour is present except now i get an exception with the message "workbox.core.registerQuotaErrorCallback is not a function".

Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info Waiting on additional information from the community.
Projects
None yet
Development

No branches or pull requests

2 participants