Reputation: 9663
Let's look at what the IndexedDB spec says about deleting a database. Specifically, I'm concerned with what happens if you try to delete a database that still has one or more open connections, like this:
indexedDB.open('test', 1);
indexedDB.deleteDatabase('test');
Here's what the spec says:
- Fire a versionchange event at each object in openDatabases that is open. The event MUST NOT be fired on objects which has the closePending flag set. The event MUST use the IDBVersionChangeEvent interface and have the oldVersion property set to db's version and have the newVersion property set to null. This event MUST NOT bubble or be cancelable.
- If any of the connections in openDatabases are still not closed, and request was provided, fire a blocked event at request. The event MUST use the IDBVersionChangeEvent interface and have the oldVersion property set to db's version and have the newVersion property set to null. This event MUST NOT bubble or be cancelable.
- Wait until all objects in openDatabases are closed and all of their transactions are finished.
I don't understand how step 7 ever completes. What is it in steps 5 or 6 that actually closes one of the open connections? What are those steps even doing besides just letting onversionchange
and onblocked
handlers respond?
Similar language appears in the steps for running a "versionchange" transaction for when you have an open connection for the database you're trying to bump the version on, like this:
indexedDB.open('test', 1);
indexedDB.open('test', 2);
FWIW, the reason I'm asking such a mundane question is because of this.
Upvotes: 3
Views: 305
Reputation: 2720
I don't understand how step 7 ever completes. What is it in steps 5 or 6 that actually closes one of the open connections? What are those steps even doing besides just letting onversionchange and onblocked handlers respond?
That's all those steps are doing. The UA fires those events and lets script close the existing connections if it wants to. If script chooses not to close the existing connections then step 7 does not complete.
This isn't described in the spec because the spec tells the UAs what to do, not script. Though it should probably be described in the non-normative Introduction.
Upvotes: 3
Reputation: 13131
My understanding is all connections must listen versionchange
event and close the connection. Otherwise newer app will neither bump new version nor delete the database. A newer app will simply get block
event, eventually. Notice that deleteDatabase
method return a Request, but close
method is not.
Upvotes: 2