Re: [IndexedDB] Closing connection in a versionchange transaction

On Fri, Nov 30, 2012 at 3:26 PM, Joshua Bell <jsbell@chromium.org> wrote:
> A spec oddity that we noticed - if you explicitly close a connection during
> an upgradeneeded handler (or elsewhere in the transaction), the transaction
> should complete (not abort) yet the connection fails (error), upgrading the
> database but leaving you without a connection.
>
> Example:
>
> var req = indexedDB.open('db' + Date.now(), 2);
> var db;
> req.onupgradeneeded = function() {
>   db = req.result;
>   var trans = req.transaction;
>   trans.oncomplete = function() { alert("transaction completed"); }; //
> should show
>   db.createObjectStore('new-store');
>   db.close();
> };
> req.onsuccess = function() { alert("unexpected success); }; // should NOT
> show
> req.onerror = function() { alert("connection error, version is: " +
> db.version); }; // should show, with 2
>
> ... and a subsequent open would reveal that the version is 2 and the the
> store exists.
>
> This behavior is specified by 4.1 "Opening a database" step 8: ...If the
> "versionchange" transaction in the previous step was aborted, or if
> connection is closed, return a DOMError of type AbortError and abort these
> steps. In either of these cases, ensure that connection is closed by running
> the steps for closing a database connection before these steps are aborted.
>
> ... and the specifics of 4.10 around closePending, which ensure that calling
> close() has no effect on running transactions.

It does seem to make sense to produce an error from a .open() call
unless the database was successfully opened. I don't feel strongly
though and don't recall why we defined it this way.

> The one spec wrinkle might be that in 4.10 "Database closing steps", the
> spec says "Wait for all transactions _created_ using /connection/ to
> complete..." where _created_ references "A transaction is created using
> IDBDatabase.transaction." which is not true of versionchange transactions.

Yeah. This should probably make sure to cover all transactions.

/ Jonas

Received on Saturday, 16 March 2013 11:40:36 UTC