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

InvalidStateError: Failed to read the 'error' property from 'IDBRequest': The request has not finished #910

Open
sopov opened this issue Oct 8, 2019 · 46 comments

Comments

@sopov
Copy link

sopov commented Oct 8, 2019

Hello,

How to properly control the size of the storage?

I have few instances of localforage,
when ~ 3mb of data (166 keys) stored I try call setItem for new key I have in developer console error.

InvalidStateError: Failed to read the 'error' property from 'IDBRequest': The request has not finished.

after this error other instance is available (exactly for reading, not sure for saving), but this instance (with error) not answer more (incl getItem), but before setItem I can request any data (getItem, keys, etc).

if I call like
localforage.setItem(..).then(console.log).catch(console.error)
catch -- never called

How do I write it right?

localforage.setItem(..).catch(
    function () {
        localforage.clean().then(function () {
            localforage.setItem(..)
        })
    }
)
  • Safari 13.0.1
@sopov
Copy link
Author

sopov commented Oct 8, 2019

I can not clear and have same issue

localforage.keys().then(function (keys) {
    console.log('KEYS: ' + keys.length)
    if (keys.length > 100) {
        console.log('CLEAR')
        localforage.clear().then(
            function () {
                console.log('DONE PAGES')
            }
        )
    } else {
        console.log('ALL IS OK')
    }
})

CleanShot 2019-10-08 at 08 18 33

@sopov
Copy link
Author

sopov commented Oct 9, 2019

I don't think it's a size of storage, maybe it's some kind of data that's stored in DB.
I try reproduce issue again, some time with less data I have same issue, now I have more 600keys & 10mb -- no issue.

@sopov sopov changed the title storage size InvalidStateError: Failed to read the 'error' property from 'IDBRequest': The request has not finished Oct 9, 2019
@carlwoodward
Copy link

carlwoodward commented Oct 11, 2019

Hey, is there any chance this the new version of Safari? I'm hitting this on iOS Safari and Desktop and I've tried multiple IndexedDB libraries and rolling my own. My test system syncs the same data between these browsers. Any thoughts?

@galfert
Copy link

galfert commented Oct 15, 2019

Safari on iOS 13 (and 12) indeed has some serious problems with IndexedDB:

https://bugs.webkit.org/show_bug.cgi?id=197050
https://bugs.webkit.org/show_bug.cgi?id=202705

@johnozbay
Copy link

I just got hit by this as well.
My findings are also in line with @sopov's.

  • It's not related to the size.

  • It seems like it could be related to the content of the item being written, because some setItem calls work some fail.

  • If setItem returns InvalidStateError: Failed to read the 'error' property from 'IDBRequest': The request has not finished. when you try to remove the same item, removeItem returns the same error.

I've just checked our live/production telemetry data, and looks like 243 users are affected by this and counting. It's happening on :

OS X Safari 13.0.1, 13.0.2 and 13.0.3
iOS Safari 13.0.1, 13.0.2 and 13.0.3

I can't see any errors from Safari 12 in our telemetry logs, neither from Safari 13.0.0 (released Sept 19), but Apple released 13.0.1 on Sept 24 (5 days after 13 was released) so there's a high chance Safari 13 introduced this bug, and we never ran into this for 5 days (or our affected users updated straight to 13.0.1)

Will keep this thread updated with further findings.
@tofumatt let me know if you need more data.

@sopov
Copy link
Author

sopov commented Oct 31, 2019

@johnozbay

  • It's not related to the size.

I confirm that I've reproduced in both small and large sizes.

  • It seems like it could be related to the content of the item being written, because some setItem calls work some fail.

It's not like that.
I did one test a couple of weeks ago, and I'm gonna tell about him from my memory.

  1. I opened a problem instance before I started working.
  2. Created a new instance
  3. Step by step rewrote all the items from the first to the second instance (get all keys and set to new)
  4. The second instance continued to allow you to setItem in it
  5. After this first instance also self-fixed

But I did it all once (not have more time), for confirm that it can help fix, it need repeat ( I didn't do it).
But that's not a good idea.
I needed a way:

  1. to understand that there was a issue (easy)
  2. an easy way to fix it (my idea for test before 1) create a new instance 2) copy data to new 3) drop first 4) create new first 5) copy back 6) drop second instance)

@C-racker
Copy link

C-racker commented Nov 5, 2019

+1

@ragexe
Copy link

ragexe commented Dec 9, 2019

Same issue on Safari 13.0.2 (macOS 10.14.6). Any updates?

@danieltamas
Copy link

Still the same issue on Safari 13.0.4 (13608.4.9.1.4) ( macOS 10.13.4 ). Any clues?

@tommulkins
Copy link

Confirmed same issue on Safari 13.0.4.

image

@tommulkins
Copy link

Confirmed same issue on Safari 13.0.4.

image

I was able to clear out this error by removing the site's data in Safari and starting fresh. Must be something conflicting with more stale data causing this.

@johnozbay
Copy link

Can confirm, clearing out site's data worked for some of our users.
Sadly, "some" – because for the rest of the users, no matter what we've tried, [Safari didn't clear the data] and the stale data kept magically coming back. It's starting to look a lot more like a Safari bug, and not a localForage bug.

@mimittqq
Copy link

can it throw this error?

@Supporterino
Copy link

@johnozbay I can confirm after deleting the data of the site the storage works again. But the error reappears over and over again. So a single wipe of the data doesn't remove the error.

@haydenth
Copy link

I'm encountering this only with users on the Google browser which (I think) uses the Safari Webview. Not encountering this with native safari or anything else. 100% of the sessions are iOS 13.3.1. This is a total mystery to me and I haven't been able to replicate, so I have no idea if this is impacting my site seriously or not. Not sure what the best course of action to resolve this bug is...

@Supporterino
Copy link

@haydenth i am experiencing this with safari on macOS with latest updates

@eeduardogarcia
Copy link

I'm experiencing this one with iOS 13.3 along with ionic 4 using angular, this one works with the android simulator but none with iOS device, neither ios simulator

@nodegin
Copy link

nodegin commented Mar 15, 2020

Getting the same error here, it looks we have to wait till AAPL release a fix

@akosbalogh
Copy link

I am getting the same error, do you have any updates on it?

@iAbhinav
Copy link

Confirmed same issue on Safari 13.0.4.
image

I was able to clear out this error by removing the site's data in Safari and starting fresh. Must be something conflicting with more stale data causing this.

Clearing site data worked for me. Thanks.

To clear data of the site

Safari > Preferences > Privacy > Manage Website Data > Select Local host > Remove All

@lincolnthree
Copy link

Also hitting this issue. Clearing site data works, but it keeps occurring - and users can't be expected to perform this clear procedure. Anyone find a workaround/fix?

@lincolnthree
Copy link

Possibly related? #874

@eeduardogarcia
Copy link

Confirmed same issue on Safari 13.0.4.
image

I was able to clear out this error by removing the site's data in Safari and starting fresh. Must be something conflicting with more stale data causing this.

Clearing site data worked for me. Thanks.

To clear data of the site

Safari > Preferences > Privacy > Manage Website Data > Select Local host > Remove All

it worked for me too

@lincolnthree
Copy link

It works, but it happens over and over again :/

@ghost
Copy link

ghost commented May 18, 2020

any news on this? Is there a workaround? I can't expect users to clear site data this way.

@tofumatt
Copy link
Member

No update yet, but I'd be curious if #874 fixes it for anyone. I'll try to review that PR this week.

@ghost
Copy link

ghost commented May 18, 2020

Excellent, thank you. I'll pay attention to #874

@ghost
Copy link

ghost commented May 19, 2020

Okay it's early days but using openKeyCursor seems to have fixed this issue for me, haven't been able to reproduce yet in the usual places.

@tofumatt
Copy link
Member

We'll probably need to do a feature check to see if it's available, agreed. But that's good to know! 👍

@lincolnthree
Copy link

Also testing openKeyCursor here. So far seems to run fine on Chrome, also haven't run out of space on Safari in a while (which is the result of this bug most frequently.)

I've been refreshing the page on Safari for about 10 minutes and have not yet reproduced. About to deploy a branch with several PRs merged in, to Beta environment, and will report back on what Sentry tells us over the next week.

@lincolnthree
Copy link

lincolnthree commented May 25, 2020

Branch, for those interested: https://github.com/lincolnthree/localForage/commits/all-fixes

@ghost
Copy link

ghost commented Jun 6, 2020

Hi guys, just letting you know - version 1.7.4 (including the mentioned PR with openKeyCursor) does not work for me unfortunately.
Clearing the Safari cache does but that is a temporary fix.
Good luck!

@Legomite
Copy link

I’m encountering this issue on iOS 13.5.1 using LocalForage 1.7.4 while calling keys() on an instance :(

@NateLevin1
Copy link

NateLevin1 commented Jul 18, 2020

I also had this issue on version 1.7.4. The solution I found was to use only one instance instead of two.
Edit: I am having the issue again. I am not sure why this worked for me before.

@lincolnthree
Copy link

@UltimatePro-Grammer Can you explain what you mean by one instance instead of two? As far as I know, we are only using one instance.

@NateLevin1
Copy link

NateLevin1 commented Jul 19, 2020

@lincolnthree I was using two separate instances, by using createInstance (e.g. foo and bar). Switching to one solved it for me (e.g. only using bar). I am not using the default localforage instance.
Edit: I am having the issue again. See below comment.

@NateLevin1
Copy link

NateLevin1 commented Jul 25, 2020

I had this issue again. I am not sure why it was fixed for me before but am having this issue again.
Edit: #938 is the same issue, but has no solution. Some more info on that thread though.

Edit 2: I have looked in to this. The actual error is thrown because the IDB request is being aborted. For some reason, Safari errors out with the error this whole thread is about when you try to access the error property on the abort object. This means there is some issue with Safari aborting and not providing an error message. Seems like a bug in Safari to me, and I'm not sure there is much we can do to get around that.

@Rafi993
Copy link

Rafi993 commented Aug 11, 2020

The really simple work around for this is to write empty value instead of trying call clear method

@NateLevin1
Copy link

@Rafi993 Actually I get this issue when using setItem, so I think what happened to you was the same that happened to me earlier where it randomly stops happening.

@Rafi993
Copy link

Rafi993 commented Aug 12, 2020

@Rafi993 Actually I get this issue when using setItem, so I think what happened to you was the same that happened to me earlier where it randomly stops happening.

Now I am having this issue too

@marci1412
Copy link

Unfortunately, I also had to deal with this issue. I wanted to add a simple entry to the objectStore "Order", but for some reason the IDBRequest got aborted each time. Instead, it showed the InvalidStateError as mentioned above. Luckily, I found a workaround where I added dummy entries to a dummy ObjectStore, just to get it working.

First, I created a new handler which provides the routine to add a test entry:

var testHandler = {
    addTest: function(test){
        var dbRequest = window.indexedDB.open("database_name.db", databaseVersion);
        dbRequest.onerror = function (event) {
            console.log(dbRequest.errorCode);
        };
        dbRequest.onsuccess = function (event) {
            var db = event.target.result;
            db.transaction('Tests', 'readwrite').objectStore('Tests').put(test);
        };
    }
};

To not needlessly fill the database storage with dummy data, I used '.put' instead of '.add' on the ObjectStore to insert resp. update the entry.

Next, I added a create statement for another ObjectStore called "Test":

// create object store only used for workaround
var testStore = db.createObjectStore('Tests', {keyPath: 'test_id', autoIncrement: true});
testStore.createIndex('test_id', 'test_id',{unique: false});

In the last step, I added the following entry at the end of the document.ready function on every page:

// add or update dummy entry
testHandler.addTest({ test_id: 1 });

As a result, my ".add" statement on the ObjectStore "Order" suddenly worked and never crashed again. I don't know why, but it seems to work for me.
I am pleased to share and hope it helps.

@NateLevin1
Copy link

@marci1412 Do you have the indexedDB code for what didn't work? We might be able to submit a bug report if we have code that isn't dependent on localForage and shows that there is an actual issue with Safari.

@dmatora
Copy link

dmatora commented Aug 23, 2020

Upgraded from 1.7.3 from 1.9.0 and it doesn't solve the issue without database removal.
Added window.indexedDB.deleteDatabase('localforage'); before localForage.setItem (I only use one key and store value at one place of the script) and that did the trick.

@mawilmouth
Copy link

Are there any updates on this? I have not been able to find a fix or work around for this.

@dmatora
Copy link

dmatora commented Oct 21, 2020

@mawilmouth number of fixes were suggested here.
btw window.indexedDB.deleteDatabase doesn't work when app is opened in more than one tab so I had to come up with more sophisticated code for that scenario

@landsman
Copy link

landsman commented Aug 31, 2021

I had the same problem when I was trying to remove whole DB:

await localforage.dropInstance({
    name: "hello"
});

but the database was removed successfully, only this annoying exception was present.

So I am using .clear() method now which does not produce any error and removes all data from DB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests