sinisterchipmunk / jax

Framework for creating rich WebGL-enabled applications using JavaScript and Ruby
http://jaxgl.com
MIT License
96 stars 16 forks source link

IndexedDB setVersion requests being blocked #37

Closed nat-n closed 12 years ago

nat-n commented 12 years ago

I'm not sure exactly what causes setVersion request to be blocked but as far as I can tell something in the Jax environment must be causing it. I've also asked about it here http://stackoverflow.com/questions/8417469/indexeddb-setversion-request-being-blocked

The following code from within after_initialize results in the onblocked event firing (and the request failing to complete thus making it impossible to initialise an object store).

  if @indexedDB and @objectStore and @key
    idb_request = indexedDB.open @indexedDB
    idb_request.onsuccess = (e) =>
      idb = e.target.result
      idb.onerror = (e) -> console.log e

      version_request = idb.setVersion(0.1)
      version_request.onblocked = (e) -> console.log e
sinisterchipmunk commented 12 years ago

Sorry, I can't reproduce this issue in either Firefox or Chrome. My initial alert(idb.version) comes up blank as you indicated in your Stack Overflow question, but then the version_request.onsuccess callback is fired. Subsequently, alert(idb.version) equals "v0.1", as the code requests.

Maybe there's something else going on in your code. Here's my complete model file:

Jax.getGlobal()['Indexed'] = Jax.Model.create
  after_initialize: ->
    @indexedDB = 'dbname'
    @objectStore = 'one'
    @key = 'two'

    # various browsers keep it
    # behind various flags and implementation varies.
    if window.webkitIndexedDB
      window.indexedDB = window.webkitIndexedDB
      window.IDBTransaction = window.webkitIDBTransaction
    else if window.mozIndexedDB
      window.indexedDB = window.mozIndexedDB

    # if @indexedDB and @objectStore and @key
    idb_request = window.indexedDB.open @indexedDB
    idb_request.onsuccess = (e) =>
      idb = e.target.result

      if idb.objectStoreNames.contains @objectStore
        store = idb.transaction([@objectStore], IDBTransaction.READ_WRITE).objectStore(@objectStore)

      else

        alert idb.version # => ""

        version_request = idb.setVersion(0.1)
        version_request.onblocked = (e) -> alert "1"+e
        version_request.onerror = (e) -> alert "2"+e
        version_request.onsuccess = (e) -> alert "3"+e
        version_request.onfailure = (e) -> alert "4"+e

    idb_request.onerror = (e) -> alert "ERROR: Unable to open indexedDB"

That's the entire model -- I generated it fresh, from the end of the Getting Started guide. It's called from a brand new controller, like so:

index: ->
  window.indexed = @world.addObject new Indexed

Please let me know if you narrow down this issue further. I'll leave this issue open for now in case it's really a Jax bug.

nat-n commented 12 years ago

Thanks for the response! After dreaming all night about asynchronous callbacks X/ it occurred to me that I'd absentmindedly tried to open and setversion the idb from within an onsucess callback from a previous opening of the same idb (with an ajax onsuccess callback in between). oops!

Strangely enough fixing this error seemed to remedy the problem in FF but not in chrome until I either changed the value of @indexedDB or restarted chrome.

So not jax's fault... although i did notice that even when the issue was remedied, reactivating the controlled without refreshing the page caused further setVersion attempts to be blocked which may or may not be an issue with the jax environment.

sinisterchipmunk commented 12 years ago

Thanks for the update. Glad to hear it's not a problem with Jax.

Interesting note about further setVersion attempts being blocked. If you end up verifying that Jax is causing the issue, please open a new issue with a link to this one.