Bug 80547 - IndexedDB: Creating a transaction from within a transaction callback should fail
Summary: IndexedDB: Creating a transaction from within a transaction callback should fail
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alec Flett
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-07 15:13 PST by Joshua Bell
Modified: 2012-06-14 01:06 PDT (History)
6 users (show)

See Also:


Attachments
Patch (18.31 KB, patch)
2012-03-07 15:16 PST, Joshua Bell
no flags Details | Formatted Diff | Diff
Patch (17.49 KB, patch)
2012-03-16 11:58 PDT, Joshua Bell
no flags Details | Formatted Diff | Diff
Patch (3.81 KB, patch)
2012-03-21 16:05 PDT, Joshua Bell
no flags Details | Formatted Diff | Diff
Patch (3.80 KB, patch)
2012-04-04 16:22 PDT, Joshua Bell
no flags Details | Formatted Diff | Diff
Patch (30.08 KB, patch)
2012-06-13 12:32 PDT, Alec Flett
no flags Details | Formatted Diff | Diff
Patch (30.41 KB, patch)
2012-06-13 15:57 PDT, Alec Flett
no flags Details | Formatted Diff | Diff
Patch (31.11 KB, patch)
2012-06-13 15:59 PDT, Alec Flett
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joshua Bell 2012-03-07 15:13:02 PST
IndexedDB: Creating a transaction from within a transaction callback should fail
Comment 1 Joshua Bell 2012-03-07 15:16:29 PST
Created attachment 130709 [details]
Patch
Comment 2 Joshua Bell 2012-03-07 15:30:27 PST
Given that this is likely to break user code, I'm not sure we should land this before the onupgradeneeded change. That said, we would like to support both setVersion() and onupgradeneeded, so maybe it's okay to land this first, with sufficient warning on the mailing lists.

And *that* said, I'm not entirely sure this is correct. As written, the patch only applies to VERSION_CHANGE transactions, i.e. those created in response to setVersion() calls. It precludes calling IDBDatabase.transaction as long as the VERSION_CHANGE transaction is active on the IDBDatabase, regardless of whether it's within the IDBVersionChangeRequest's callback or a dependent IDBRequest's callback. The text in https://www.w3.org/Bugs/Public/show_bug.cgi?id=11401 only applies to the Sync API. 

I'll follow up on the mailing list.
Comment 3 Joshua Bell 2012-03-07 15:40:38 PST
Ah, the spec now says re: IDBDatabase.transaction()

"This method must throw a DOMException of type InvalidStateError if called before the success event for a open call has been dispatched."

That applies to the newfangled approach:

req = indexedDB.open(name, version);
req.onupgradeneeded = function () {
   var db = req.result;
   // better not call db.transaction here
   var putreq = db.createObjectStore(...).put(...);
   putreq.onsuccess = function () {
     // better not call db.transaction here
   };
};
req.onsuccess = function () {
   var db = req.result;
   // you can finally call db.transaction now
};

The upshot being that you can't call db.transaction while a VERSION_CHANGE transaction is running. This matches the patch's behavior change in spirit, even though the API is radically different.

So I'm okay with landing this, now or later.
Comment 4 David Grogan 2012-03-08 14:37:15 PST
LGTM

(I looked through this last night but forgot to LGTM it.)
Comment 5 Joshua Bell 2012-03-16 11:23:45 PDT
tony@, r?

Opinions on landing this now? I'm still torn between inflicting pain now vs. later.
Comment 6 Joshua Bell 2012-03-16 11:58:59 PDT
Created attachment 132339 [details]
Patch
Comment 7 Joshua Bell 2012-03-16 12:00:14 PDT
Comment on attachment 132339 [details]
Patch

FYI, latest patch is just a rebase/merge against the recent test refactoring.
Comment 8 Tony Chang 2012-03-16 12:37:33 PDT
Comment on attachment 132339 [details]
Patch

The code looks fine.  I defer to your judgement about whether to land now or after onupgradeneeded is supported.  If there aren't that many clients, it might be OK to land this now.
Comment 9 Joshua Bell 2012-03-21 16:05:32 PDT
Created attachment 133135 [details]
Patch
Comment 10 Joshua Bell 2012-03-21 16:09:04 PDT
Comment on attachment 133135 [details]
Patch

Just a rebase on top of r111225 which took care of the test updated.
Comment 11 Joshua Bell 2012-04-04 16:22:13 PDT
Created attachment 135709 [details]
Patch
Comment 12 David Grogan 2012-04-05 14:00:23 PDT
Comment on attachment 135709 [details]
Patch

LGTM
Comment 13 Joshua Bell 2012-04-18 11:04:42 PDT
Handing this off to dgrogan@ - let's land it at the same time as onupgradeneeded.
Comment 14 Joshua Bell 2012-06-07 14:27:30 PDT
Alec's going to take ownership of this w/ the error cleanup he's doing, and probably slip this in.
Comment 15 Alec Flett 2012-06-13 12:32:53 PDT
Created attachment 147390 [details]
Patch
Comment 16 Alec Flett 2012-06-13 13:23:52 PDT
jsbell@ / dgrogan@ - mind taking a look?
Comment 17 Joshua Bell 2012-06-13 13:51:31 PDT
Comment on attachment 147390 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=147390&action=review

overall lgtm

> Source/WebCore/Modules/indexeddb/IDBTransaction.cpp:86
> +    , m_mode(mode)

Add ASSERT in constructor that m_mode == m_backend->mode() ?

> LayoutTests/storage/indexeddb/mozilla/resources/remove-objectstore.js:-47
> -            if (++addedCount == 100) {

Remove other uses of addedCount in this file (and -expected.txt)

> LayoutTests/storage/indexeddb/resources/database-basics.js:32
> +

Nit: remove blank line
Comment 18 Alec Flett 2012-06-13 15:57:46 PDT
Created attachment 147435 [details]
Patch
Comment 19 Alec Flett 2012-06-13 15:58:34 PDT
Comment on attachment 147435 [details]
Patch

jsbell's issues addressed.

tony@ - r? cq?
Comment 20 Alec Flett 2012-06-13 15:59:46 PDT
Created attachment 147436 [details]
Patch
Comment 21 Alec Flett 2012-06-13 16:00:08 PDT
Comment on attachment 147436 [details]
Patch

ooops, forgot to update expectations.

new patch, tony@ - r? cq?
Comment 22 WebKit Review Bot 2012-06-14 01:06:22 PDT
Comment on attachment 147436 [details]
Patch

Clearing flags on attachment: 147436

Committed r120295: <http://trac.webkit.org/changeset/120295>
Comment 23 WebKit Review Bot 2012-06-14 01:06:28 PDT
All reviewed patches have been landed.  Closing bug.