OneSignal-Website-SDK icon indicating copy to clipboard operation
OneSignal-Website-SDK copied to clipboard

InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase'

Open pedromcunha opened this issue 5 years ago • 19 comments

I noticed in our error tracker I get these errors roughly 50/hour.

Error · Uncaught (in promise): InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing. Error: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing. at Promise (https://cdn.onesignal.com/sdks/OneSignalPageSDKES6.js?v=150701:1:42046)

It's happening 100% of the time on all versions of Chrome (Mac and Windows), for anonymous and logged in users of our web app. Any idea what's happening here?

pedromcunha avatar Mar 13 '19 15:03 pedromcunha

Any update on this @rgomezp ?

pedromcunha avatar Mar 25 '19 13:03 pedromcunha

@pedromcunha We have only seen this error if you clear your browser data (either as a whole or specifically for your site).

Are you able to reproduce the issue in any other cases? If so can you provide the full steps to reproduce and a full stack trace?

Thanks.

jkasten2 avatar Mar 25 '19 18:03 jkasten2

Closing due to inactivity

rgomezp avatar Apr 18 '19 17:04 rgomezp

I guess the question is why is the error not caught within the OneSignal code itself (as opposed to a js console error) and if such occurs why is there no error handling provided to the user and particularly to the back end OneSignal server to remove the user from the OneSignal active or subscribed users so that they can restart the process from the client side

connetcom avatar Apr 29 '19 00:04 connetcom

We have made a note of this issue internally and plan to fix it in the future. Thanks for your input

rgomezp avatar Apr 29 '19 20:04 rgomezp

Hey! any updates about this bug? I've got the same one, in case user first visit the site we've got this issue, in other cases everything is fine.

Paxarik avatar Jul 23 '19 14:07 Paxarik

Thanks for your patience while we resolve

rgomezp avatar Jul 30 '19 20:07 rgomezp

@Paxarik , @connetcom , @pedromcunha , I'm not sure exactly where the error is coming from. Could you provide a stack trace of the error? Also please turn on logging using OneSignal.log.setLevel('trace') so we can have the full context

rgomezp avatar Aug 07 '19 22:08 rgomezp

in running my own PWA with DB and service worker, i notice this error in my own code which occasionally occurs after i do a reset storage and then restart the PWA. The issue for me occurs when the DB is created and then the datastore is attempted to be accessed but the datastore has not finished being created yet (is all async). Maybe this is something to look at - i.e., the timing of the access to a data store or putting some promise or something to make sure the datastore is created before access.

connetcom avatar Aug 08 '19 11:08 connetcom

@connetcom , Thanks for the details. This is a rare error so it seems like it is only happening in certain setups. Do you suspect this is related to your app being PWA?

rgomezp avatar Aug 12 '19 22:08 rgomezp

Sorry for late reply, so, in a sense, yes it has to do with the PWA and more particularly with the testing of the PWA because it only occurs when the DB gets recreated after i manually do a clear storage in the debugger. As said, i am not quite sure but i believe it has to do with the Async nature of how the calls to the DB are made and a lot seems to be going on when the PWA is coming up which might (?) cause some delays. Also, it would seem certainly possible to code around this (which i assume that the onesignal code does not and i have not gotten around to doing myself but did think about a bit and certainly seems feasible) by not attempting to use the datastore until the DB has actually completed the creation of the datastore (would seem some promise could handle this). So, I have not really had an issue with it in the production code but knowing that it can happen on my test system does not give a warm fuzzy about the likelihood of it never happening in production. I would say that OneSignal should spend the time to resolve it.

connetcom avatar Aug 15 '19 13:08 connetcom

@connetcom , We haven't ever heard of this happening in a case other than after clearing data. And even then, this should be resolved as soon as a new tab is opened. If you have reproduced this outside of the one case, please let us know. Otherwise, this isn't something we are considering as a top priority.

rgomezp avatar Aug 15 '19 21:08 rgomezp

Closing due to no response

rgomezp avatar Sep 23 '19 23:09 rgomezp

See update in #716 -- let's try to get a min-reproducible.

jmadler avatar Nov 23 '20 23:11 jmadler

See also update in #671

jmadler avatar Nov 23 '20 23:11 jmadler

@rgomezp Hi! this issue happens on a ReactJS app (Google Chrome, MacOS) as well. Please consider that a final user can clear the cache but not necessary open a new tab which will result on devtools showing InvalidStateError: Failed to execute 'transaction' on 'IDBDatabase' maybe in the future the users will open a new tab but there's a high change they don't do it the first time.

The React code I'm working on is not a PWA nor has an DB connection besides the one from OneSignal. The React app is just a demo app I'm creating for an article I'm writting

devpato avatar Jan 24 '21 05:01 devpato

Hi!

So this issue also happened when we cleared out the cache and local storage for our PWA built on Angular 9. Is there any remedies or fixes to stop this from happening?

OneSignalBug

naudej avatar May 21 '21 13:05 naudej

Hello,

Something similar also happening to me (Similar to #671 which is closed as a duplicated of this issue).

I am using OneSignal with NextJS 11.1.2 and React 17.0.2 This only happens to me on Safari Version 15.1 (17612.2.9.1.20) on MacOS.

Here is my browser's console log output:

[Error] Database PUT Error: – NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. — IndexedDb.js:180
NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found. — IndexedDb.js:180transaction(anonymous function) — IndexedDb.js:180Promise(anonymous function) — IndexedDb.js:178generatorResumer — tslib.es6.js:62promiseReactionJob
	error
	(anonymous function) (OneSignalPageSDKES6.js:1:48040)
	Promise
	(anonymous function) (OneSignalPageSDKES6.js:1:47842)
	generatorResume
	r (OneSignalPageSDKES6.js:1:721)
	promiseReactionJob
[Error] Unhandled Promise Rejection: NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
	generatorResume (OneSignalPageSDKES6.js:1:47888)
	a (OneSignalPageSDKES6.js:1:768)
	promiseReactionJob
[Error] Unhandled Promise Rejection: NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
	generatorResume (OneSignalPageSDKES6.js:1:47082)
	a (OneSignalPageSDKES6.js:1:768)
	promiseReactionJob
[Error] Unhandled Promise Rejection: NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
	generatorResume (OneSignalPageSDKES6.js:1:47082)
	a (OneSignalPageSDKES6.js:1:768)
	promiseReactionJob

I explain a bit about my setup:

I have ServiceWorkers within my /public directory:

./public
├── OneSignalSDKUpdaterWorker.js
├── OneSignalSDKWorker.js
├── favicon.ico
└── vercel.svg

I followed this article to implement.

I'm loading the script within my App component (pages/_app.tsx) and this is what I'm returning:

return (
    <>
      <Head>
        <title>irrelevant</title>
        <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async />
      </Head>
      <Layout>
        <Component {...pageProps} />
        <Toaster />
      </Layout>
    </>
  );

The Head component is imported from next/head.

and I have my useEffect within my App component (pages/_app.tsx) like this:

useEffect(() => {
    window.OneSignal = window.OneSignal || [];
    const OneSignal = window.OneSignal
    OneSignal.log.setLevel('trace')
    OneSignal.push(() => {
      OneSignal.init({
        appId: "CENSORED.",
        safari_web_id:
          "CENSORED",
        notifyButton: {
          enable: true,
          displayPredicate: () => !!window.localStorage.getItem("accessToken"),
          position: "bottom-left",
        },
        allowLocalhostAsSecureOrigin: true,
      });
    });

    return () => {
      window.OneSignal = undefined;
    };
  }, []);

Note: Yes, I replaced the IDs with CENSORED.

Since I'm using TypeScript, I had to do const OneSignal = ..., but I also tested without that line, same result.

I can provide more info or even a MCRE if required.

DarkSuniuM avatar Nov 01 '21 05:11 DarkSuniuM

I'm also having this issue, i get it on sentry

jcardus avatar Nov 07 '22 15:11 jcardus