Reputation: 4129
Since today I've started getting errors when I try to delete IndexedDB database in Google Chrome version 21. When i run the command for deleting database:
window.webkitIndexedDB.deleteDatabase(dbName);
The following event fires:
IDBVersionChangeEvent
bubbles: false
cancelBubble: false
cancelable: false
clipboardData: undefined
currentTarget: IDBVersionChangeReques
defaultPrevented: false
eventPhase: 2
returnValue: true
srcElement: IDBVersionChangeRequest
target: IDBVersionChangeRequest
timeStamp: 1343929274696
type: "blocked"
version: ""
Additional info: I am accessing the IndexedDB from web workers and from window.
Upvotes: 2
Views: 3093
Reputation: 4129
The problem was in the accessing the database from the web workers. In this line of code:
database.close();//closing the database
self.close();//closing the web worker
There is probably some bug in Google chrome if database closing needs more time than usual and you close the web worker, then the database is locked when you try to delete it afterwards.
I've fixed the problem by not closing the web worker and let it stay in idle mode.
Upvotes: 0
Reputation: 2720
It means there is an open connection to that database somewhere. It could be in a different tab than the one that's calling deleteDatabase. That connection received a versionchange event notifying it that a call to deleteDatabase had been made and that it needs to close.
You can add such a handler when the database is opened:
request = indexeddb.open("dbname");
request.onsuccess = function(event) {
db = event.target.result;
db.onversionchange = function(event) {
event.target.close();
}
}
Upvotes: 4