Bug 143126

Summary: IndexedDB: index creation fails after multiple versionchange events
Product: WebKit Reporter: Taylor Buley <taylor.buley>
Component: New BugsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: beidson, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
some IDB js to run in console none

Description Taylor Buley 2015-03-26 21:00:58 PDT
Created attachment 249548 [details]
some IDB js to run in console

Background: I've found it challenging to keep IDB database connections open for reuse and have instead come to adopt a pattern where every open connection is closed after a single transaction (such as creating an object store or index) has been committed and fired its `complete` event. This is somewhat unorthodox compared to common patterns of reuse seen on the web but my IDB library is very old and time has told me this is the sanest approach when dealing with multiple tabs, etc. As a result, my typical "install code" chains together a number of consecutive `versionchange` transactions, one to create the database and one for each store and index.

I've been having trouble creating indexes in iOS8. The problem I see is that my indexes all create fine and and the transactions commit successfully as well but after all is said and done only the index for the last transaction to commit is available on the object store.

Attempting to create a test case for this, I've managed to cobble together something that throws an interesting error in WKWebViews in iOS 8.2 after a couple `versionchange` events. The expected result, confirmed as successful in recent Chrome and Firefox builds, would be a database on version `3` with an object store and two indexes. Instead, in the WKWebView a `NotFoundError` is thrown: "DOM IDBDatabase Exception 8: An operation failed because the requested database object could not be found."

The console.logs show this database as existing and on the correct version number prior to a failed opening after the second `versionchange`. I'm not sure it's exactly the issue I was attempting to document, but it seems at least related as it also appears for me when creating indexes after multiple `versionchange` events.

https://gist.github.com/buley/eca47cda4979c74174c6
Comment 1 Radar WebKit Bug Importer 2015-04-25 14:59:21 PDT
<rdar://problem/20699776>
Comment 2 Brady Eidson 2016-06-01 15:21:51 PDT
This should be working fine with modern IDB.

Please try in a WebKit nightly or Safari Tech Preview.